1

Respected seniors!

I have hosted a website on GCE and storing all static content on GCS bucket. The content is then accessed using google API link e.g https://storage.googleapis.com/[BUCKET_NAME]/[OBJECT_NAME]...

Now the API link is embedded on webpage on my website as https://www.example.com/post/[random post number](this is an html link which I need to serve an updated copy every time so I set up a cookie to avoid caching in CDN)

I have enabled Cloud CDN on my load balancer backend GCE. My understanding was that the link embedded in webpage for static content will automatically be cached in CDN because the bucket access is made public.

Upon verifying using cURL I came to know that whenever I access the object using API link (https://storage.googleapis.com/[BUCKET_NAME]/[OBJECT_NAME]), the content is cached in CDN and whenever I use my site link (https://www.example.com/post/[random post number]), the content is not cached.

Kindly suggest any method to cache the content on bucket in clod CDN whose link is embedded in dynamic content url which has to be fetched fresh every time.

Thanks in advance

  • You need to enable CDN on the bucket as well: https://cloud.google.com/cdn/docs/setting-up-cdn-with-bucket – elithrar Jul 02 '20 at 01:55
  • Sir I am not serving site directly from storage bucket. The kink you provided is for serving the site from bucket as back-end. I am serving site from google computer engine and storing static content in bucket. The static content is then fetched using API link embedded in webpage...adding bucket as backend will make load balancer to send request to bucket directly I guess??? – Shams ul hassan Jul 02 '20 at 08:42

1 Answers1

0

Based on your description, this look like working as intended. The reason why the content is not being cached is due to cookies header being present. This article explain when content is non-cacheable: https://cloud.google.com/cdn/docs/caching#non-cacheable_content

This is also confirmed when you mentioned:"(https://storage.googleapis.com/[BUCKET_NAME]/[OBJECT_NAME]), the content is cached in CDN." The bucket doesn't have any cookies and this is why it's cached.

  • Hello sir! Thanks for your response. Actually I hosted my site firstly using ssd storage for saving static content and that was being cached properly giving site speed a huge bump. After that I integrated google bucket for static content and felt a little lag in loading static content and upon verifying using cURL, I came to know that static content is being served from bucket, every time it is requested. I have gone through the links you provided.The request mechanism is same when using ssd and bucket, but static links are not being cached in bucket case while they do in ssd – Shams ul hassan Jul 07 '20 at 17:59
  • According to your answer 1.Static content should not be cached because of a cookie or a dynamic html link(but it did when using ssd as storage) 2.Content stored in a public bucket should be cached in automatically i. it is being cached when you access it directly using https://storage.googleapis.com/[BUCKET_NAME][OBJECT_NAME] ii. not when the above link is pasted in a dynamic webpage url. What I am looking for is a solution that the pasted link should trigger CDN caching – Shams ul hassan Jul 07 '20 at 18:10
  • There could be many reason why this is happening. I would suggest you to review all of the requirements and restriction for Cloud CDN. - https://cloud.google.com/cdn/docs/overview - https://cloud.google.com/cdn/docs/caching Also, you can follow the troubleshooting located in this article [https://cloud.google.com/cdn/docs/troubleshooting-steps]. – Ilia Borovoi Jul 10 '20 at 03:42