hridayesh
hridayesh

Reputation: 1143

Error in Disable browser cache for a Cloud CDN's object (via Google Cloud Storage's bucket)

I have a bucket in Google Cloud Storage, and serving its content via Google Cloud Load Balancing having above bucket as backend. All the objects in the bucket are public. JS, CSS, HTML and images are stored in a bucket.

Since Cloud CDN doesn't support gzip compression (afaik) so I have uploaded gzipped files to bucket with appropriate headers.(All my users use browser which supports gzip compression)

I want to disable cache(specifically caching in user's browser, but no caching in Google's lb is also fine) for few js files. For that I have added below headers to the object in bucket

Content-Type    application/javascript;charset=UTF-8
Content-Encoding    gzip
Content-Language    en
Cache-Control   private, max-age=0, no-transform, no-cache, no-store, must-revalidate

Even after this browser is getting public cache headers with 1 year expiry. I tried sending same request via curl and below are the results.

curl -v --request GET \
  --url https://cdn.intelliticks.com/prod/common/client/inject.min.js \
  --header 'Accept: */*' \
  --header 'Cache-Control: no-cache' \
  --header 'Connection: keep-alive' \
  --header 'Host: cdn.intelliticks.com'

returns correct caching headers. but below request(with accept-encoding header which is added by browsers by default)

curl -v --request GET \
  --url https://cdn.intelliticks.com/prod/common/client/inject.min.js \
  --header 'accept-encoding: gzip, deflate' \
  --header 'Accept: */*' \
  --header 'Cache-Control: no-cache' \
  --header 'Connection: keep-alive' \
  --header 'Host: cdn.intelliticks.com'

returns with 1 year caching. Any way to remove caching headers so that browser doesn't cache it?

Upvotes: 1

Views: 1051

Answers (1)

bhito
bhito

Reputation: 2673

Google Cloud CDN supports gzip if you put the correct header Content-Encoding: gzip when doing a request, however it is specified that objects should weight less than 10MB when specifying gzip encoding.

Regarding caching, there are some situations in which even if you specify no-cache, the content can be eligible for caching. For example, when using a signedURL the objects are then eligible to be cached.

Also objects are cacheable if they are publicly available, as it is your case. Maybe you can try to put the bucket as publicly readable and then specify the Cache-control header to each of the objects. Also you can try changing your objects from public to private, therefore they are not eligible for being cacheable and then give access only to the range of users you wish.

Upvotes: 1

Related Questions