Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

158
Views
Angular - How to cache an image indefinetly, regardless of the server's response headers

I have an angular application on my own domain, that displays images from google storage like this:

<img src="googleUrl..."/>

The default Cache-Control is set to 3600 seconds which is way too low for me, because I want to cache the images for 1 week (the images on the storage change very rarely).

I tried to create an HttpInterceptor but it does not intercept the request that the src of the img makes.

I also tried to create a pipe and set a Cache-Control header but, the server being google, it gives me a Cross-Origin error. This is how I implemented it:

@Pipe({
    name: 'cacheResource',
})
export class CacheResourcePipe implements PipeTransform {
    constructor(private http: HttpClient, private sanitizer: DomSanitizer) {}
    transform(url): Observable<SafeUrl> {
        const headers = new HttpHeaders({
            'Cache-Control': 'public, max-age=2.592.000',
        });
        return this.http
            .get(url, {
                headers,
                responseType: 'blob',
            })
            .pipe(map((val) => URL.createObjectURL(val)));
    }
}

And then called like this:

<img [src]="'googleUrl.com' | cacheResource | async" />

(The pipe approach works with files stored on the same domain but I don't have this possibility)

Is there any way to achieve the long cache that I need without changing the server?

about 4 years ago · Santiago Gelvez
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!