Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Leverage Browser Caching in Firebase hosting

I have hosted my personal blog on Google's firebase. My Blog is based on jekyll. Firebase provides firebase.json file from where owner of project can modify the http header.

I have my css files https://blogprime.com/assets/css/init.css and my fonts in https://blogprime.com/assets/font/fontname.woff ( http cache control not working )

My images are stored inside :: https://blogprime.com/assets/img/imagename.entension ( http cache control working ).

Even though both images and css, fonts are two dir deep from root.

Now heres my .json file code..

{"hosting":      {"public": "public",     "headers": [         {"source" : "**/*.@(eot|otf|ttf|ttc|woff|css)",         "headers" : [             {"key" : "Access-Control-Allow-Origin",             "value" : "*"}]         },          {"source" : "**/*.@(jpg|jpeg|gif|png)",         "headers" : [             {"key" : "Cache-Control",             "value" : "max-age=30672000"             }]         },          {"source" : "404.html",         "headers" : [             {"key" : "Cache-Control",             "value" : "max-age=300"             }]         }]     } } 

Before adding this my images and everything had 1hour of cache lifespan.... but now only my css files along with font files are having 1 hour cache lifespan.

Can you please tell me how to fix the "Leverage Browser Caching" for my css files. I think their's some problem with the directory link structure which I have "source" : "/*.@(eot|otf|ttf|ttc|woff|css)",**. I really don't know how to fix it.

You can check the Google pagespeed test ..

https://developers.google.com/speed/pagespeed/insights/?url=https%3A%2F%2Fblogprime.com%2Fwordpress%2Fdns-prefetch-in-wordpress.html

like image 839
John Adam Avatar asked Nov 02 '16 08:11

John Adam


People also ask

How do I leverage browser caching?

To leverage your browser's caching generally means that you can specify how long web browsers should keep images, CSS and JS stored locally. That way the user's browser will download less data while navigating through your pages, which will improve the loading speed of your website.

Does firebase do caching?

Firebase Hosting uses a powerful global CDN to make your site as fast as possible. Any requested static content is automatically cached on the CDN. If you redeploy your site's content, Firebase Hosting automatically clears all your cached static content across the CDN until the next request.

How do I leverage browser caching in Wordpress?

Navigate to General Settings and select Enable Browser Cache. Click save and navigate to Browser Cache Settings (top of the page) Choose the cache headers available. Set expires headers, cache-control, and ETag headers (based on the settings done before)

Does firebase cache read?

This feature caches a copy of the Cloud Firestore data that your app is actively using, so your app can access the data when the device is offline. You can write, read, listen to, and query the cached data.


1 Answers

I just make my portfolio website 99/100.

Google says:

We recommend a minimum cache time of one week and preferably up to one year for static assets.

    "headers": [ {       "source" : "**/*.@(eot|otf|ttf|ttc|woff|font.css)",       "headers" : [ {         "key" : "Access-Control-Allow-Origin",         "value" : "*"       } ]     }, {       "source" : "**/*.@(js|css)",       "headers" : [ {         "key" : "Cache-Control",         "value" : "max-age=604800"       } ]     }, {       "source" : "**/*.@(jpg|jpeg|gif|png)",       "headers" : [ {         "key" : "Cache-Control",         "value" : "max-age=604800"       } ]     }, {       // Sets the cache header for 404 pages to cache for 5 minutes       "source" : "404.html",       "headers" : [ {         "key" : "Cache-Control",         "value" : "max-age=300"       } ]     } ] 

Use this, it works for me.

like image 117
alfaiz momin Avatar answered Oct 13 '22 22:10

alfaiz momin