How do I add “Expires” Headers? – Website Performance Enhancement
-
January 28, 2020 at 6:37 am #1536
[anonymous]
Recently I’ve been optimising my small hobby website. I ran it through PingDom by Solarwinds and it spat out the attached screenshot. Can anyone give me any advice on how to add “Expires Headers” to my website?
Thank you in advance for your valuable time.
January 28, 2020 at 6:45 am #1538
[anonymous]
Please run the analysis on GTmetrix once
January 28, 2020 at 6:48 am #1539January 28, 2020 at 7:34 am #1542
[anonymous]
Thank you ajeet!
I’ve done that, image is here:
January 28, 2020 at 7:41 am #1544
[anonymous]
I am using Netlify to host my site. You can add expired headers by adding a _headers.toml file in the root of your site.
https://docs.netlify.com/routing/headers/
Attaching a file for your ref. Modify it. ( use your site name.)
Download the file from here and edit it using any text editor. This should solve some issues but not all.
https://send.firefox.com/download/1cbbcef009f5e425/#VrY4_qYfLwAN1QkHEDAZ9A
January 28, 2020 at 10:59 am #1555
[anonymous]
I’m also using Netlify.
I’ve grabbed the file you listed and changed my address. How do I actually upload it directly into my Netlify Account?
January 28, 2020 at 3:31 pm #1560
[anonymous]
Here is how to upload
Publii > Tools > Root Directory > Upload Files
Ignore the image I have attachedMake sure to check your site is accessible here: https://www.responsinator.com
Some rules in Headers makes the site unavailable, but I have excluded the rule. I wont go into the details now. Later probably.
Pls let me know if that works.
January 29, 2020 at 1:05 am #1569
[anonymous]
Mate, you’re a legend! Worked perfectly, changed your file with my website name, set the values to a weeks expiry, and pushed it with the instructions above. Thank you!
I’ll paste the text of your file below in case anyone else finds it useful. Should be saved to a file called
_headers
/*
Content-Security-Policy: default-src ‘self’ ‘unsafe-inline’ ‘unsafe-eval’ https: data:
X-Frame-Options: *ALLOW-FROM https://www.YOUR WEBSITE GOES HERE.net*
X-XSS-Protection: 1; mode=block
Referrer-Policy: strict-origin-when-cross-origin
Expect-CT: max-age=0
Vary: Accept-Encoding
X-Content-Type-Options: nosniff
Strict-Transport-Security: max-age=604800; includeSubDomains; preload
Feature-Policy: accelerometer ‘none’; camera ‘none’; geolocation ‘none’; gyroscope ‘none’; magnetometer ‘none’; microphone ‘none’; payment ‘none’; usb ‘none’/img/*
Cache-Control: public, max-age=604800, immutable/*.pdf
Cache-Control: public, max-age=604800, immutable/*.ico
Cache-Control: public, max-age=604800, immutable/*.flv
Cache-Control: public, max-age=604800, immutable/*.jpg
Cache-Control: public, max-age=604800, immutable/*.jpeg
Cache-Control: public, max-age=604800, immutable/*.png
Cache-Control: public, max-age=604800, immutable/*.css
Cache-Control: public, max-age=604800, immutable/*.js
Cache-Control: public, max-age=604800, immutable/*sw.js
Cache-Control: public, max-age=604800, immutable/*.html
Cache-Control: public, max-age=0, must-revalidateJanuary 29, 2020 at 1:11 am #1570
[anonymous]

I do a lot of Google ๐
And just for everyone’s info, there are several guide to tweak the Cache Control thing,, Some are:
https://www.gatsbyjs.org/docs/caching/
Glad it worked for you..
February 10, 2020 at 3:52 am #1680
[anonymous]
Thank you Ajeet, that was a real help and I’ve since helped several friends do this with their Publii sites. Thank you!
February 10, 2020 at 9:56 am #1681
[anonymous]
Your always Welcome ๐
