How do I specify expiration for my css & image files?

12 replies
  • WEB DESIGN
  • |
I heard that specifying expiration for image and css files is a good practice. But I do not understand this. I would like to know how to specify this?

Adi
#css #expiration #files #image
  • You can do this in your htaccess file ....

    # Expire images header
    ExpiresActive On
    ExpiresDefault A0
    ExpiresByType image/gif A2592000
    ExpiresByType image/png A2592000
    ExpiresByType image/jpg A2592000
    ExpiresByType image/jpeg A2592000
    ExpiresByType image/ico A2592000
    ExpiresByType text/css A2592000

    A2592000 means 1 month in the future (60*60*24*30=2592000)
    {{ DiscussionBoard.errors[3616994].message }}
    • Profile picture of the author adianadiadi
      Originally Posted by Cash Money Hosting View Post

      You can do this in your htaccess file ....

      # Expire images header
      ExpiresActive On
      ExpiresDefault A0
      ExpiresByType image/gif A2592000
      ExpiresByType image/png A2592000
      ExpiresByType image/jpg A2592000
      ExpiresByType image/jpeg A2592000
      ExpiresByType image/ico A2592000
      ExpiresByType text/css A2592000

      A2592000 means 1 month in the future (60*60*24*30=2592000)
      Thank you very much sir. May I know what is the benefit of doing so?
      {{ DiscussionBoard.errors[3627223].message }}
    • Profile picture of the author adianadiadi
      Originally Posted by Cash Money Hosting View Post

      You can do this in your htaccess file ....

      # Expire images header
      ExpiresActive On
      ExpiresDefault A0
      ExpiresByType image/gif A2592000
      ExpiresByType image/png A2592000
      ExpiresByType image/jpg A2592000
      ExpiresByType image/jpeg A2592000
      ExpiresByType image/ico A2592000
      ExpiresByType text/css A2592000

      A2592000 means 1 month in the future (60*60*24*30=2592000)
      When I added this to my htaccess file, I encountered:

      Internal Server Error

      The server encountered an internal error or misconfiguration and was unable to complete your request.

      Please contact the server administrator and inform them of the time the error occurred, and anything you might have done that may have caused the error.

      More information about this error may be available in the server error log.

      So what is wrong with my file?
      {{ DiscussionBoard.errors[3633458].message }}
      • Profile picture of the author Lloyd Buchinski
        Originally Posted by adianadiadi View Post

        So what is wrong with my file?
        Just a guess, but from your post it sounded like you loaded his whole post into the .htaccess file. You should only add this part.

        Code:
        # Expire images header
        ExpiresActive On
        ExpiresDefault A0
        ExpiresByType image/gif A2592000
        ExpiresByType image/png A2592000
        ExpiresByType image/jpg A2592000
        ExpiresByType image/jpeg A2592000
        ExpiresByType image/ico A2592000
        ExpiresByType text/css A2592000
        And related to another question you asked, the benefit of doing this is that if you change something on your site, visitors will see the new version sooner. A browser often caches style sheets or pages. It will sometimes show the older version until the visitor forces a refresh or the time set in the htaccess above runs out.
        Signature

        Do something spectacular; be fulfilled. Then you can be your own hero. Prem Rawat

        The KimW WSO

        {{ DiscussionBoard.errors[3640591].message }}
        • Profile picture of the author adianadiadi
          Originally Posted by Lloyd Buchinski View Post

          Just a guess, but from your post it sounded like you loaded his whole post into the .htaccess file. You should only add this part.

          Code:
          # Expire images header
          ExpiresActive On
          ExpiresDefault A0
          ExpiresByType image/gif A2592000
          ExpiresByType image/png A2592000
          ExpiresByType image/jpg A2592000
          ExpiresByType image/jpeg A2592000
          ExpiresByType image/ico A2592000
          ExpiresByType text/css A2592000
          No. I have added only the above part. I found even adding the first line "ExpiresActive On" makes my site start giving error messages.
          {{ DiscussionBoard.errors[3641556].message }}
  • Profile picture of the author jargonbust
    use expire active on command
    {{ DiscussionBoard.errors[3627342].message }}
  • Profile picture of the author DigiMixus
    My site's hosted with GoDaddy too. I'm going to try out the code and see how it works. Thanks for sharing!
    Signature
    @michaelsalafia
    Wordpress Web Design
    Strategist / Designer / Growth Hacker @ DigiMix NYC
    {{ DiscussionBoard.errors[6661814].message }}
  • Profile picture of the author DigiMixus
    I added expire image code to my .htaccess file then ran a Google Page Speed Test and it immediately increased my page speed from 83/100 to 85/100. But it's registering that I am not setting some of the .jpg's to expire.
    Signature
    @michaelsalafia
    Wordpress Web Design
    Strategist / Designer / Growth Hacker @ DigiMix NYC
    {{ DiscussionBoard.errors[6661919].message }}
  • Profile picture of the author AllenMack
    Hi my friend i believe you want to speedup your website dont you

    well adding expiry of different files on your.htaccess file is the one thing only..... if you test your website from gtmetrix or https://developers.google.com/speed/pagespeed/insights/ you will see there are tons of minifications and customization required with your website CSS, Js files, images, CDN connectivity and many more.... well here's the one solution that i have for you

    go with WP Rocket plugin and try any Cloud hosting ones you will see the brilliant difference of speed on your website.
    {{ DiscussionBoard.errors[10714596].message }}
  • Profile picture of the author ITDaniel
    I have never actually thought about expiraton of files haha, i am glad that I stumbled on this topic. I will make sure that I try this.
    {{ DiscussionBoard.errors[10741757].message }}

Trending Topics