Soliloquy - The Best Responsive WordPress Slider Plugin

How to Leverage Browser Caching in WordPress via .htaccess

Share This Post

We should always be looking for ways to improve the functionality of our blogs. One of the easiest ways to improve our blog functionality and speed is to leverage browser caching.

Another way of saying this is that we add expires or cache control headers for our blog. In Layman’s terms, by leveraging browser caching, we can reduce the number of HTTP requests that the server needs to process, thus reducing loading times and improving user experience and website performance. And as an added bonus, when we leverage browser caching, we improve our scores on PageSpeed and YSlow!.

In order to do this, we will need to modify our .htaccess file and add in the appropriate directives.

Finding and Modifying .htaccess

For those that are not tech savvy, modifying the .htaccess file might seem a little daunting. In reality, it is quite simple. For this tutorial, if you can cut and paste correctly, you should be worry-free.

You can access your .htaccess file through cPanel by clicking on the File Manager. When the popup box appears, click on the Web Root option and make sure that the “Show hidden files” option is checked.

Pasting in the Directives to Leverage Browser Caching

Open up your .htaccess file and paste in the following directives at the top of the file:

By using this code, our main static files (images, CSS, PDF’s, JS, etc.) will be cached in order to produce faster loading times in the future.

Now save your .htaccess file and view your site through the eyes of PageSpeed and YSlow! – you are now leveraging browser caching for your site!

It is easy to leverage browser caching in WordPress with this tutorial – enjoy!

Have you enjoyed reading How to Leverage Browser Caching in WordPress via .htaccess? Sign up below to get regular content updates and also get my "7 Tips to a Professional WordPress Setup" absolutely free!

About Thomas Griffin

I live and breathe WordPress. I create products around WordPress (Soliloquy and OptinMonster), contribute to WordPress core and do lots of fun development around WordPress in general. You can find me on Twitter, Facebook and Google+.

  • Paul

    Hi Thomas
    Very interesting. i knew nothing about this.
    Can you give a brief explanation of what PageSpeed and Yslow are.

    • Thomas Griffin

      Sure, no problem. :)

      PageSpeed and YSlow! are both add-ons to Firefox and Chrome that allow you to test the performance of your website. Of the many things that they analyze, one of them is to see if you leverage browser caching. Each of these development tools are used to help you optimize your site for the best possible performance across web browsers and internet connections.

      Hope this is helpful for you!

  • Andreas

    Great tip!

    Exactly what I was looking for. Missed that part in my optimizing process, so thanks!
    However, for some reason the javascript files wasn´t included (they showed default value) so I changed the default to 1 month. Quick and dirty fix, but it works..


  • David

    I looked in htaccess and found some code from W3 Total Cache – a plugin I removed a while ago. So I chopped it out and put in your code and wondered all the while at my recklessness, even as I did it.

    All seems to be OK.

    Thanks :-)

  • Jonathan

    Thanks for the tip. I’m looking for everything that I can use to cache our site.

  • Pingback: Awesome WordPress hacks to make your blogger life easier -

  • Pingback: Wordpress, sfruttare la cache del browser con .htaccess - Realizzazione siti web Catania - siti web, creazione e realizzazione siti internet, professional freelancer web developer, sviluppatore web

  • Pingback: Awesome WordPress hacks to make your blogger life easier | CSS Citadel

  • Pingback: 17 Great Wordpress Hacks You Might Need Some Day | DesignBeep

  • pc-manden

    I ended up with an 500 Server Side Error ?

  • pc-manden

    By wrapping it up in an IF-statement, you won’t get a 500 error if it’s not supported. If the expires module isn’t active, it won’t help you, but at least you don’t get any errors by using it.

    Like this:

    ExpiresActive On
    ExpiresByType image/jpg “access 1 year”
    ExpiresByType image/jpeg “access 1 year”
    ExpiresByType image/gif “access 1 year”
    ExpiresByType image/png “access 1 year”
    ExpiresByType text/css “access 1 month”
    ExpiresByType application/pdf “access 1 month”
    ExpiresByType text/x-javascript “access 1 month”
    ExpiresByType application/x-shockwave-flash “access 1 month”
    ExpiresByType image/x-icon “access 1 year”
    ExpiresDefault “access 2 days”


    • Thomas Griffin

      Thanks for pointing that out! I will update the post to include the conditional statement. I guess I just figured most servers would have mod_expires, but I suppose some shared servers still neglect to allow that directive to customers.

  • pc-manden

    Sorry, won’t show the ‘wrapping’ codes in comments:

    (IfModule mod_expires.c)
    - expires statements –

    and swap the ( and ) with

  • pc-manden

    LOL cant write those arrows! :-)
    You have to use arrows around the IFs…

  • Vincent

    So do we or do we not include th if statement?
    (IfModule mod_expires.c)

    • Thomas Griffin


      Yes, you should include the statements in order to keep from returning 500 server errors in case you don’t have the module activated. I actually had it in the original post, but I forgot to escape the HTML, which removed that statement!


  • Pingback: Caching a Dynamic Website. Does it Make a Difference for Loading Speed? « Boutros AbiChedid

  • Pingback: SFCite | Blog | Shun the Plugin: 100 WordPress Code Snippets from Across the Net

  • Sagive SEO

    Thanks a lot man! finally something easy to read and easy to follow.. i went from 82 to 84 in my page speed :)

    Cheers, Sagive

  • roland

    Should your pagespeed and the announcement in Google Pages Speed improve directly? After adding this script to the .htaccess nothing changes for my website.

    • luis

      did you get this figured out? , I am having the same issue

      • Jamie

        Me 3, my overall score did not increase from 61 to 61, in my leverage browser caching whet from 27 to 38, but overall score did not improve, any help or recommendations for (very image heavy site)

  • Lorraine Cheney

    Cool – I was struggling to get my Page Speed sorted and by removing the W3 Total Cache code from my .htaccess and adding yours I went from 76% to 83%. All my sites will use this from now on.



  • Jc

    I have set this code for css. i surf my website it is running fine. then i changed something in css, but changes are coming in the website although i cached it. it means no cache done. can you please explain why i am not getting cached css contents?

  • Pingback: Awesome WordPress hacks to make your blogger life easier | redbey

  • rdd

    Please somebody tell me that How can I get the cache type(1min cache,5min cache,….) of the whole page or of a part in a website??

  • Harsha – Tech

    Hmm.. I will check this now.. if works.. You are simple genius,., If not it means I dont even know to copy paste correctly ;)

  • anupal

    well done !! nice thanxx

  • luis

    Hello, I placed this code in both the .htaccess file on thehome folder and the .htaccess file in wp-content/cache… I am still getting a recomendation on Yslow and Pagespeed to leverega browser chache, any idea why, and how can I check if it is working?
    Thanks so much

    • Kev

      Same here! It’s very frustrating. I have setup W3 Total Cache which is great (warning to those using themes with ajax drop down menus though) but for some reason the browser caching isn’t working according to GTMetrix and Google Page Speed.

      I tried placing this code in the .htaccess file but no changes.
      I tried replacing the W3 browser cache info with this code in htaccess – no change

      Do I need to disable W3 Total Cache in order for this to work – seems kinda counter productive since it works very well with most other things. I really would like someone to help – is this something from the ISP perhaps?

  • phill

    Thanks Thomas, this worked a treat. Finaly got my Google page speed score above 90 :)

  • velos

    very nice and thank you ……
    It has helped improve my pagespeed Site

  • Shibby

    Very usefull code, but does the W3TC Caching plugin does his or should i add it?

  • James

    Anyone able to rewite this in zeus?

  • Prüfung

    This is exactly what i was looking for. Thanks for sharing. I have one question about it though. I understand that whenever i reload the page it will show the cached files. But will it work to reload the files from the server again by pressing CTRL + F5?

  • Ashley Karyl

    Thanks for showing how this is done. I’ve just added this code across all my sites and not had any problems, however I did find it quite esasperating while testing using the Page Speed Tools because the results were telling me that browser caching was not being leveraged in some cases even when it clearly was. I had the same issue with Gzip compression which has been enabled across all my sites.

    After roughly an hour of confusion while trying to understand this in FireFox Page Tools I tried Google’s own and found it was giving different results. Then I tried using the same extension for Chrome and found yet again it wasn’t the same, so in the end I had to conclude I had done as much as possible and leave it at that…

    • Prüfung

      hi ashley, i used to check loading times. its easy to understand and gives good advice to speed up your website. this might help… ;)

      • Ashley Karyl

        Thanks for that link Prüfung. I’ve been having a play with some of my sites to see how they perform there.

        My interest in this came about through some frustration at viewing my site performance stats inside the Google webmaster tools where it showed one of my domains was slower than 90% of the sites on the web. This grated my pride because I had gone all out for efficiency and the sites were hosted on a high end dedicated server, so it should have been screaming fast. Google was saying that one of my sites took an average of nearly 8 seconds to open but I could never understand how they were finding it so slow when it was opening almost instantly for me. I wondered if they are still on a 28K modem?

        Now I’ve made these changes I want to wait and see if my scores improve inside the webmaster tools. I probably shouldn’t worry about it but it was really bugging me and I wondered if it was affecting my search ranking.

  • Sandeep

    After adding this code to .htaccess my page speed is decreased from 78/100 now it is 70/100 and still red icon showing expiry problem. I tested on both YSlow and Google Page speed. Please help

    • Ashley Karyl

      That doesn’t sound right Sandeep. On one of my sites with properly optimised images I am now scoring 99/100 and before that it was around 82.

  • sudha

    If you can leverage browser caching, you can increase website speed considerably. As Google starts considering site speed as a SEO parameter, webmasters can leverage browser caching to improve site speed and get better search engine rankings.

  • Ashley Karyl

    I’ve just been looking at this again and it looks as though browser caching is working on my home page but not other pages. Anybody know why that might be?

  • Rein

    Thank you so much for this; in Pingdom Tools Pagespeed my Leverage browser caching score went from 17 to 42 after using your code.

    There are however a lot of recources that still have a hort freshness lifetime, but I’m not sure why. The bulk of them are (cropped?) images, like these:


    Got about 20-25 of these.
    Any idea how I can improve those as well? :)
    Much appreciated!

    • Joseph

      Try WP It’s a image compression style plugin that helps reduce the amount of crap that images can carry. I’ve just had my host moan at me for using too much MySQL CPU Usage on the shared server so I’ve been doing some tips and tricks everywhere over the last few days so I recommend that as it does help a little.

      All just to save those few extra milliseconds! It’s almost laughable!

      I’m about to try this code and I hope it to work. I’ve got the WP Super Cache plugin and I’m including this code at the very top as you suggest

  • Susan

    Thank you – I just implemented this on one of my sites and already noticed a change in speed.

  • Joseph

    If I my ask, how long am I likely to have to wait to see a noticeable difference if any?

    • Joseph

      I noticed today that the speed score has improved but I am still getting a medium priority on Google Page Speed and it is stating that;

      “The following cacheable resources have a short freshness lifetime. Specify an expiration at least one week in the future for the following resources:”

      And it lists css, js and png’s that : (expiration not specified)

      So I’m unsure whether it is actually working or not.

  • Prasanna SP

    After adding this to .htaccess, my site page speed decreased from 91 to 86!!! Strange.. Google Page Speed test now suggesting me to leverage browser caching.. :-(

  • Nadiar

    Nice work,.. i don’t thnking .httacess can do that

    let see the ressult…

  • Tom

    Hey Thomas, not tried this form of browser caching before but now that I’m trying to increase the performance of my WordPress blog I’ll certainly give it a go. Can I ask though, how do you specify a single file?

  • Izzy

    what happens if I edit a file, say the css or change a picture after adding the code to the .htaccess file? the browsers won’t show the edited files until the expire date? that can’t be right, what do I need to do when I change something?

  • Alaska Tech Support

    If you are using Joomla – edit htaccess

    Header unset ETag
    Header unset Last-Modified

    FileETag None

    Header unset Cache-control
    Header set Expires “access plus 1 month”

  • Alaska Tech Support

    For Joomla

    Header unset ETag
    Header unset Last-Modified

    FileETag None

    Header unset Cache-control
    Header set Expires “access plus 1 month”

  • Pingback: How to Make Your WordPress Website Faster

  • Phoenix

    Hi Thomas,
    Thanx for this trick,
    92 my page speed rank now
    thank you so much.

  • premium wordpress plugin

    This has been quite helpful – thanks for helping speed up my site!

  • Richard

    Hey! Thanks for the tips.

    I have the following code in my “.htaccess” file:

    # To set your custom php.ini, add the following line to this file:
    # suphp_configpath /home/yourusername/path/to/php.ini

    # BEGIN WordPress

    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ – [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]

    # END WordPress

    Should the code your recommending be in addition to this on a new line outside of the # END WordPress, or should the WordPress Code be removed completely? If someone could email me, that’d be great — thanks:

  • Tams

    Thank you for posting this! It worked perfectly to eliminate the error I received in PageSpeed for Leveraging my Browser. I’m glad someone knew how to do this easily. Thanks again.

  • Pingback: Page Speed SEO | My Monkey Do

  • Melvin Tan Property Agent Singapore

    Hi Thomas,
    Greatly thanks for your tricks. My page score improve tremendously after pasting the code into .htaccess of all my wordpress site.
    I should have found this earlier.

  • Caroline

    Hi there,

    I am afraid I get a 500 Server Error when I paste your code into my .htaccess file.

    I have tried pasting it above and below the other code in the file, as well as only including your code in the file.

    This is the code already in my .htaccess file:

    # BEGIN WordPress

    RewriteEngine On
    RewriteBase /wordpress/
    RewriteRule ^index\.php$ – [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /wordpress/index.php [L]

    # END WordPress

    Hope someone can help!

    • Caroline

      FYI I included your code just in your post. The if statements have been stripped out.

      • David Vildebrand

        If you strip out the if statements and then get a 500, it is very likely your webserver does not have the mod_expires module enabled. You’ll need shell/root access to do this. Research “apache enable modules” for additional information.

    • Michael

      To hit 2 flies in 1 attempt, i will suggest, hitting both mod_expire. mod_mime and mod_deflate:

      Options -Indexes

      RewriteEngine On
      RewriteBase /
      RewriteRule ^index.php$ – [L]
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteCond %{REQUEST_FILENAME} !-d
      RewriteRule . /index.php [L]


      # Enable expirations
      ExpiresActive On
      # Default directive
      ExpiresDefault “access plus 1 month”
      # My favicon
      ExpiresByType image/x-icon “access plus 1 year”
      # Images
      ExpiresByType image/gif “access plus 1 month”
      ExpiresByType image/png “access plus 1 month”
      ExpiresByType image/jpg “access plus 1 month”
      ExpiresByType image/jpeg “access plus 1 month”
      # CSS
      ExpiresByType text/css “access 1 month”
      # Javascript
      ExpiresByType application/javascript “access 1 month”

      AddType application/x-javascript .js
      AddType text/css .css

      SetOutputFilter DEFLATE

      SetEnvIfNoCase Request_URI .(?:rar|zip)$ no-gzip dont-vary
      SetEnvIfNoCase Request_URI .(?:gif|jpg|png)$ no-gzip dont-vary
      SetEnvIfNoCase Request_URI .(?:avi|mov|mp4)$ no-gzip dont-vary
      SetEnvIfNoCase Request_URI .mp3$ no-gzip dont-vary

      Header append Vary User-Agent env=!dont-vary

      # END WordPress

      # And i would also add a blocking of lipwww-perl:

      # Bloker lipwww-perl
      SetEnvIfNoCase User-Agent “^libwww-perl*” block_bad_bots
      Deny from env=block_bad_bots

  • Pingback: .htaccess and browser caching | PHP Developer Resource

  • Ante

    I have added this code to my .htaccess file, and I noticed that my page is lot faster, but when I use is still says that I have to enable leverage browser caching. Any idea??

    • Richard Vencu

      it says so for the external resources only (gravatar, etc)

      • Owen Prescott

        Do you recommend using an alternative to gravatar etc? I am trying to optimize the speed to improve UX and SEO.

    • The Web Design Group

      It also depends which elements it says still require browser caching? I have had it where the js libraries have need the additional adding to the above code:

      ExpiresByType application/x-javascript “access 1 month”

      ExpiresByType application/javascript “access 1 month”

  • salvatore

    Good hints, I would like to note that in some case Google PageSpeed Insights does NOT “see” changes immediately. You can also use W3 Total Cache plugin if you use WordPress as an alternative, and it works well.

  • Pingback: How To: Leverage Browser Caching in Wordpress Without Plugins

  • wirowiro

    Wow, That is very easy to do and the result is wonderful. Thank you very much.

  • wpshouter

    finally it worked tnx a ton dude :) i was searching last few hours for this solution.

  • Sharanyan Sharma

    It works well, I just added those .htaccess codes to my blog and it’s loading very fast.

  • TechGopal

    thanks for this …

  • Free-Market Guy

    Thanks so much for your browser caching code for .htaccess

  • Easter Joke

    Awesome Thanks

  • Pingback: How to speed up WordPress Apache

  • Pingback: Leverage Browser Caching | FC <3 WP

  • Ejikeme Princely

    This is a very nice article on htaccess i like your article.

  • Xava Ireland

    Hi there – works fantastically well for me. Thanks so much. My site has improved a lot.

  • Rachael Cleveland

    Thank you! It took me a second to realize you can edit the .htaccess file after right clicking. That might help other readers. So glad for this easy code!

  • Avinash Kumar

    where is the code ?

  • Wonderful Mumbai

    How does one do this for a Windows server (IIS)?

    Thank you.

  • aditya bajaj

    hey i added the code to my htaccess. it has improved. but still there are some js and gif images for which it says to leverage browser cache. pls help.

  • Imran Aftab

    Thanks a lot Thomas, for such a nice and clear guide :)

  • Lukas Mühle

    Thanks a lot for this information.

  • Pingback: 3 Simple ways to improve your WordPress blog speed | Webdev2

  • PS3 Repair Guide

    Great, thanks for your support, I got rid of the RED point, now is yellow, I noticed this at the bottom line:

    ExpiresDefault “access 2 days” : You get yellow Point instead of the Red point BUT:

    If you set it to 1 month you absolutely get rid of yellow/red exclamation points. I hope this helps somebody

    ALSO I have a question, since my site is an affiliate WordPress site, how or where can I set cookies or something so my affiliate links don´t die after two days, but over the whole year, which is the maximum time allowed by the RFC guidelines. (I really don´t have an idea of what is that anyway).

    But as an affiliate remember that the last link that takes the customer to the sale is the one that gets paid, and if your cookies or affiliate links die after 2 days or 1 month, so you hope to last till the end.
    I don´t really know if I´m being clear enough.

    Thanks for your support, great article and WATCH OUT on the other result on Google, I tried before right now another code and my website got down, i got the 500 error, I erase the code and it got up again, and paste the code on this website and got rid of the red points, change then the last line and set it for 1 month and got rid of the yellow point.
    Thanks and cheers.

  • Nerd Glasses Fashion

    Thanks a ton!!! After trying hard to configure W3 Total Cache i just removed the plugin and inserted the code. Page Speed 92/100!

  • Pinoy_MEME

    wow working fine on my blog. thanks bro for this big help…keep sharing..

  • arunkallarackal

    Thanks a lot friend! Worked perfectly on my blog!

  • Abinash Mohanty

    Thanks Thomas for the tips! I have added the rules and tested, my speed got 95% from 93% Awesome! :)

  • Abinash Mohanty

    Hi Thomas, I am facing up with one issue here, there is one page where the google form was embedded and now after the code has been added i am getting this error message in place of the form “Unable to process Google Form. Server is responding with403 Permission Denied error.”

    It is happening because of the dynamic google form?

  • Maxwell Purrington

    Now if only the author had only told those of us who are not tech savvy how to access the “cpanel.”

  • Villas Diani

    Thank you very much for this Thomas, I am trying to follow up your instruction but it is rather confusing. You say I should open the .htaccess file in web root but from the hostgator they say me I should do it in .htaccess of the public_html of the domain Can you please help me to clarify this? Thank you so much!

    • BatchHeader

      The public_html folder is your web root. Anything above that is ont visable from the web

  • Pingback: Leverage Browser Caching in WordPress via .htaccess | Hot Clone ThemesHot Clone Themes

  • foodintolerance

    it doesnt do anything.. i have wp super cache.. is this a problem?

    • Týr

      Improved my huge widgitized news page score to 92/100

      Reduced EU visitors load times by 5-7 seconds

  • Týr

    Why does my admin bar disappear on my front page after this mod? It is great mod improved my site performance score from 85 to 92/100 and 74% faster than all sites, this is a widgetized news site big front page running 30+ widgets. size 2.1MB

    I imagine being main page cached may have something to do with it. I can leave a window open of just go to a page other than home or a post and admin bar shows fine.

    Thanks for mod

    • griffinjt

      Yes – it is definitely because your browser has cached that page. Just clear out your browser cache and you should be good to go.

      • Týr

        So this means any new content published or media added needs auto refresh of page? Thanks for reply first I have seen of this method.

        • Týr

          Just noticed this messes with my WP Touch plugin which is a must have the on/off mode does not work properly have to hit on or off then do a manual refresh normal people can’t figure this out excellent caching though but will have to drop for this reason. Also enabled wptouch restricted which prevents anything from interfering and does the same the stuff if you know of a way to stop this please let me know but still excellent work here,

  • gaurang

    i use this code….but my shopping cart is not working properly…

  • Kim Butler

    Excellent article and instruction. This sped up every website I own and manage.

  • ChicRenegade

    Thank you soooooo much!!!!

  • Pingback: How To Speed Up Your Wordpress Site In Less Than 2 Minutes | KeshKesh

  • Takeshi Young

    Thanks for this, this was very helpful! Didn’t realize it would be so easy!

  • Diana

    I have WP super cache but this does not get rid of the (No max-age or expires) messages in webpagetest. I found your code that seems to be to solve ALL my problems but I worry if this is compatible with the WP super cache plugin? I am very afraid to break anything since I would not have a clue on fixing it. I spent 2 whole days trying to speed up my site but it is still very slow…
    Thanks for any help!

  • Pingback: Mejorando la velocidad de carga

  • Gaurav Srivastava

    @jthomasgriffin This is such an incredible post man!!!!!!!!!!!! Thanks.

    Should I still need W3 Total Cache or not, please suggest

  • branduxd

    Thank you so much, i have added the code into my .htaccess file. it’s working fine now.
    And i need another help. if you can help me out it would be great, i am trying to enable gzip but i don’t know what are the steps to complete.

    • Michael

      This will hit both mod_expire, modmime and mod_deflate, this way you will get your comptession on gzip, (note, on apache server), the last 3 lines blocks for bad bots, you can delate that, if you dont know them ;-)

      RewriteEngine On
      RewriteBase /
      RewriteRule ^index.php$ – [L]
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteCond %{REQUEST_FILENAME} !-d
      RewriteRule . /index.php [L]


      # Enable expirations
      ExpiresActive On
      # Default directive
      ExpiresDefault “access plus 1 month”
      # My favicon
      ExpiresByType image/x-icon “access plus 1 year”
      # Images
      ExpiresByType image/gif “access plus 1 month”
      ExpiresByType image/png “access plus 1 month”
      ExpiresByType image/jpg “access plus 1 month”
      ExpiresByType image/jpeg “access plus 1 month”
      # CSS
      ExpiresByType text/css “access 1 month”
      # Javascript
      ExpiresByType application/javascript “access 1 month”

      AddType application/x-javascript .js
      AddType text/css .css

      SetOutputFilter DEFLATE

      SetEnvIfNoCase Request_URI .(?:rar|zip)$ no-gzip dont-vary
      SetEnvIfNoCase Request_URI .(?:gif|jpg|png)$ no-gzip dont-vary
      SetEnvIfNoCase Request_URI .(?:avi|mov|mp4)$ no-gzip dont-vary
      SetEnvIfNoCase Request_URI .mp3$ no-gzip dont-vary

      Header append Vary User-Agent env=!dont-vary

      # END WordPress

      # Bloker lipwww-perl
      SetEnvIfNoCase User-Agent “^libwww-perl*” block_bad_bots
      Deny from env=block_bad_bots

  • opencodez

    Great technique. I am trying this on my site. Will update you on perfomance.

  • Justin

    Hi Thomas,

    My ht access file looks like this:

    RedirectMatch 301 ^/([0-9]{4})/([0-9]{2})/(.*)$$3

    # BEGIN WordPress

    RewriteEngine On
    RewriteBase /
    RewriteRule ^index.php$ – [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]

    # END WordPress

    Should I place the cache code you gave above the redirectmatch?

  • jay

    Wow thanks for your information- you the man!!!!!!

  • jay

    im at 71/100 how can i improve the site?

  • Jorge A. Gonzalez

    Thanks! Wondering why this isn’t done by WordPress out of the box.

  • David Trounce

    Great Work. So simple. Thanks a bunch. I use quick cache and was hesitant to modify the .htaccess since Quick Cache also offers some expiry fixes. So, I only entered the image expirations and that lifted my speed by 2%….

    Not much, I know, but, as my grandmother used to say… “Every Mickle makes a Muckle.” It all adds up. Thanks Thomas. If I could afford you, I would hire you!

  • Chanel @ La Viajera Morena

    This was a really easy to use and understand post. Going to follow your site :)

  • Andrej Mikula

    Google wants me to cache CSS as well. How can I do that please?

  • iPhone4ever

    Hope this works for my website

  • Muhammad Waqas Baig

    wao amazing, i have tried at least half of dozen of plugins including w 3 total cache on my blog but everyone had its own hitch. can’t believe it was that simple. bravo man =D

  • Shutter Muse

    Maybe this is a silly question but if you set CSS to be one month, and you modify a CSS file, how do you force it to look at the newly updated CSS file?

    • Shutter Muse

      Incidentally, I’m stoked you are the man behind OptinMonster because a lot of my site speed issues came from Popup domination and OptinSkin. The fact that you are blogging about page speed lets me know that you care about that and this is great for OptInMonster as I’m sure you will try and keep it nice and speedy :)

  • SñIþêr Pal

    Hello Thomas
    CODE is already good but can you act like this code to blogger?

  • Pingback: How to Leverage Browser Caching in WordPress via .htaccess | Antonio J |

  • Pingback: How to Leverage Browser Caching in WordPress via .htaccess Antonio's Journal |

  • Sam Crowe

    Where is the tutorial with the code? I’m not seeing it in the page above.

  • Robert Conway

    Can I access my .htaccess file with my site?

  • sirsha

    Thanks you very much. It was a very easy tutorial. I could implement in a few seconds and also see results.

  • someshl

    This didn’t worked out for me.
    Please assist.

  • Skatz Saravana

    It’s great… tested and found good

  • Bret Painter

    Hi, I’ve see a couple of people ask this but no answer. I’m running WP Super Cache also and have paste the code in at the top of the .htaccess but PageSpeed Insights are still telling me to leverage browser caching? –

  • Daniel Dibble

    Yeee Haa. Worked like a champ! Thank You!

  • mndawood

    Hello, I am hosting my WordPress site on .Net environment, where web.config is used in place of .htaccess .. please advise on how can I modify this syntax to fit in a web.config?

  • Mohammed Saimon

    Great post. Thank you

  • Gaurav Srivastava

    I did the same thing with two ways. One, you said via htaccess, and second using Wp-total cache. Is it Ok or I have to use only one tactic? Which one is better BTW!! I am applying both on my blog. Waiting for your kind response..!

  • Nicolas Martin

    Worked like a charm on! The minute before I integrated the code in the .htaccess file, my “Browser Caching” score on pingdom was merely 20/100. Now it reached 70/100! Great improvement. One question: can this be improved even further (I’m thinking of something like 90/100) or are there limits?

    • Nicolas Martin

      Alright, quick edit since my message (one minute ago): my “Browser Caching” score on pingdom is now 88/100! I guess my server needed a bit of extra time to sort/tag all cachable items and serve them to the browser. Score is now really awesome. Thanks again!

  • Pingback: DIY: How to Optimize Your Company’s Wordpress Website, For Free

  • Robert Hunter

    Really nice. That made PageSpeed Insights happier. Cheers!

  • Mona Ali
  • Pingback: 5 Tips to help speed up your wordpress blog! | Social Media Outdoors


    Ca-tching! This got rid of my “You should leverage browser caching” on! Thanks a bunch!

  • MonitorPT

    Completely works for me! Thanks

  • Marcel

    Does this work if I’m not using wordpress? If so why, mention wordpress so much if it works for all Apache servers?

  • Amit Ramani

    Thanks for this post. Even after these changes, the Leverage Browser Cache warning is active for the Javascript (.js) resources. Any ideas?

  • Ulises

    Thank you so much Thomas for this short but straight forward article. So helpful, my website improved exponentially speed wise!

  • johnny

    Tank`s alot This is wath I need :*

  • simon

    make a big difference to my site speed. Thanks for sharing.

  • Daniel chez Couteau de chasse

    Thanks for this. great information. I have implemented and have reach over 80 scores on all pages of my website. the only problem that remains is this. I get the below message from pagespeed and not sure how to remove it as these are third party websites

    Leverage browser caching
    Setting an expiry date or a maximum age in the HTTP headers for static resources instructs the browser to load previously downloaded resources from local disk rather than over the network.
    Leverage browser caching for the following cacheable resources:… (15 minutes) (30 minutes) (30 minutes) (60 minutes)…e:rpc:shindig.random:shindig.sha1.js?c=2 (60 minutes) (2 hours)