williamli
williamli

Reputation: 4122

firebase hosting cache error

I have deployed some JS assets in my Firebase Host.

For some JS files, I have been getting If you go to https://organicdot.com/assets/landing-page/startup/common-files/js/jquery.bxslider.min.js?_=1402542893115 you will get a Error 503 Connection Time Out error.

If you go to the same address, but without the timestamp in the end, https://organicdot.com/assets/landing-page/startup/common-files/js/jquery.bxslider.min.js the file will get served without any problems.

Upvotes: 0

Views: 1897

Answers (1)

Chris Raynor
Chris Raynor

Reputation: 1695

Adding the timestamp to the URL will cause Firebase Hosting to treat each subsequent fetch of the file as a different resource. While we might change this in the future, that currently means that any edge server on the CDN will proxy a response from our origin servers on the east coast of the US each time it gets a request, effectively removing the benefits of using a CDN.

When you deploy new content to Firebase Hosting, we purge any cached copies of the old file across the whole CDN instantaneously, and given the default Cache-Control header is max-age=3600, the longest any well behaving client could be using an old copy of a file is 1 hour. The simplest solution to reap all the rewards of the CDN whilst also ensuring fresh content is to not put the timestamp in the URL.

In the near future, we'll also be adding the ability to modify the Cache-Control headers, so if 1 hour is still too long you'll be able to tell the browser not to cache the content at all (with the trade-off of higher data-transfer rates). Ignoring any query parameters on the URL at the CDN level is something else we're considering.

As for how long a deploy takes - the files should be ready as soon as the progress meter in firebase-tools or on the Hosting dashboard completes (besides a round-trip to our origin servers on the first fetch from each edge server). There may, of course, be caching at the browser level.

Upvotes: 2

Related Questions