Sign in

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

  • This topic has 10 replies, 2 voices, and was last updated 2 weeks ago by .
Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
    Posts
  • #1536
    TinyBatz

    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.

    Attachments:
    #1538
    ajeet

    Please run the analysis on GTmetrix once

    #1539
    ajeet

    Post the image of this under YSLow COlumn,

     

    gt

    #1542
    TinyBatz

    Thank you ajeet!

    I’ve done that, image is here:

    Attachments:
    #1544
    ajeet

    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
    TinyBatz

    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
    ajeet

    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.

    Attachments:
    #1569
    TinyBatz

    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
    ajeet

    :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
    TinyBatz

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

    #1681
    ajeet

    Your always Welcome 🙂

Viewing 11 posts - 1 through 11 (of 11 total)
  • You must be logged in to reply to this topic.