Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Quickly Update Static Site on Google Cloud Storage?

I have a static site hosted on google cloud storage. I set it up per the same methodology described here:

https://cloud.google.com/storage/docs/hosting-static-website

I have purchased a domain, and the website is running smoothly on it at this point. I am still in the process of making changes to the content of the site. My current workflow is to edit the files (for example, index.html) locally on my windows machine, and then upload the modified files to my storage bucket using the online console/ storage browser at https://console.cloud.google.com/storage/browser, making sure to set them as public links. I then navigate to my website using chrome to see what changes have occurred.

Most of the time, when I do this, my site appears to be unchanged! I can even inspect the source files for the site and discover that they do not match the files that are currently in my storage bucket. If I wait some time, varying from minutes to hours, the website does eventually change. I would like it to be the case that it changes instantly so I can test changes quickly (I cannot test locally because the framework I am using does not function without running a localhost, which I cannot do). How do I do make my cloud storage static site update quickly?

My best guess for the reasons this might happen are pretty scattershot. Is it that it takes some amount of time for various gcp servers around the world to sync together? Would it have anything to do with the TTL settings or other settings on my domain name registrar? (namecheap, currently using defaults).

like image 442
Bill Tedinator Avatar asked Aug 13 '17 13:08

Bill Tedinator


1 Answers

While it's not impossible for the propagation of the changes inside the GCS infrastructure to account for the behaviour you mention it's rather unlikely.

It's more likely you're looking at a cache effect. Which can happen:

  • inside the Google cloud:
    • work around it using a made up extra URL query parameter, like ?ignoreCache=1, see https://stackoverflow.com/a/37124554/4495081, or
    • see Cache-Control and Editing object metadata if you want a more permanent solution (but which also affects your site's performance, so think twice about what you're doing)
  • in your browser - try clearing your browser's cache after deployments
  • pretty much anywhere in between (and you have no control over this).
like image 145
Dan Cornilescu Avatar answered Sep 18 '22 12:09

Dan Cornilescu