Download
We're evolving to serve you better! This current forum has transitioned to read-only mode. For new discussions, support, and engagement, we've moved to GitHub Discussions.

How do I add “Expires” Headers? – Website Performance Enhancement

  • #1536
    Avatar photo[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.

    #1538
    Avatar photo[anonymous]

    Please run the analysis on GTmetrix once

    #1539
    Avatar photo[anonymous]

    Post the image of this under YSLow COlumn,

    gt

    #1542
    Avatar photo[anonymous]

    Thank you ajeet!

    I’ve done that, image is here:

    #1544
    Avatar photo[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

    #1555
    Avatar photo[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?

    #1560
    Avatar photo[anonymous]

    Here is how to upload

    Publii > Tools > Root Directory > Upload Files
    Ignore the image I have attached

    Make 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.

    #1569
    Avatar photo[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-revalidate

    #1570
    Avatar photo[anonymous]

    :mrgreen:

    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/

    https://medium.com/pixelpoint/best-practices-for-cache-control-settings-for-your-website-ff262b38c5a2

    Glad it worked for you..

    #1680
    Avatar photo[anonymous]

    Thank you Ajeet, that was a real help and I’ve since helped several friends do this with their Publii sites. Thank you!

    #1681
    Avatar photo[anonymous]

    Your always Welcome ๐Ÿ™‚