Firebase hosting instantly makes available a new version of your website the moment you deploy it. At the same time, you are able to instantly roll back to a previous version. Usually a CDN requires several minutes before changes are propagated and the same applies for .htaccess files or similar that could do redirects making me think that they have a dynamic extra layer on top of the CDN. If they do, how might they handle the DNS stuff?
You have a custom domain name that uses a CNAME to reach Firebase's mysite.web.app and Firebase probably uses a CNAME to forward to Fastly's (Firebase's CDN provider based on a network lookup) domain e.g. firebase-customerid-mysite.fastlycdn.net
I can't exactly figure out how they deal with the instant version changes. They must use different folders in the CDN but I don't think they use a different subdomain for each version as that would require a new certificate etc and would not be so fast. So how do you redirect a whole domain to a subfolder? You could do that by changing the .htaccess file but that would also require several minutes. How do you think they do it?
Thanks in advance!
CodePudding user response:
As far as I can sum it up firebase version change is similar to that of a git so no they don't create a different directory to deploy your latest version they just save the previous version in the .firebase or something folder (version control directory) and the subdomain doesn't change. Instead, the latest version gets deployed which changes we can see immediately due to no-cache
which generally needs to be validated with the origin server before each reuse. So when the browser asks fastly, it checks with the firebase server if the resource has changed and if yes a new version of that resource is provided.
References:
https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control
https://firebase.google.com/docs/remote-config/templates
https://docs.fastly.com/en/guides/how-fastlys-cdn-service-works
To achieve a similar result one can use git for version control (changes in real-time) and use the no-cache
header (for resource validation). We can use any CDN as nearly all of them validate the resources.