Today, I would like to speak a few things about browser caching/leverage browser caching and the reason why we must not use it and the most effective way to turn it off completely.
Alright…No doubt, browser caching improves page speed in the browser and how does it happen actually, is it the real page speed of that website when the browser caching is enabled? The real page speed could be a lot slower than usual and here browser caching helps to speed up the page loads. Browser caching stores all the necessary things in the browser and it shows all the pages from those stored copies. This can create a serious problem. I talked about it in a few posts here earlier though, 1) “A better plugin” and 2) “Leverage browser caching“.
Once when you will add/update/delete something and the browser caching is turned on, it is you who is seeing the changes in your website on that same browser where you develop that website or it is the browser where you have got the dashboard of that website (for example, a WordPress dashboard) but the old users who previously visited your website from different locations, are not seeing those changes and whenever they visit your website, they are often/always displayed only those old cached/stored copies from the past. Until users clear the browser cache from “all-time”, this problem is not solved and at this point, you cannot explain users about this problem as well, it is because updates are not reaching to the old users who were affected by this browser caching. New users or a new browser will receive the updates but after a while, it would be affected by the browser caching as well. Where do I need a browser caching let’s see. For example, I have a website completely ready and I would never make any changes to this website anymore. It means it is a website that is truly fixed with the fixed contents forever which will never change and nothing would be added/deleted/updated there and there would be nothing latest. In such cases, browser caching/leverage browser caching can improve performance and speed significantly. Once again, it is not any real page speed of that website.
Yes, here is the easiest but the most effective way to turn browser caching/leverage caching completely off, and to do that we will add the following lines at the bottom of the .htaccess file. It effectively helps in many ways, one of the examples, you have a caching plugin installed and that activated browser caching, in that case, these lines below in the .htaccess file would naturally deactivate that browser caching from that plugin. It might show that the browser caching is enabled in the plugin’s “settings” but in reality, after adding these lines to the .htaccess file, browser caching will not work anymore, regardless of where it is coming from.
So, let’s add these following lines to the .htaccess file and these would be placed at the bottom of the .htaccess file.
<IfModule mod_headers.c> Header set Cache-Control "no-cache, no-store, max-age=0, must-revalidate" Header set Pragma "no-cache" Header set Expires 0 </IfModule> <IfModule mod_expires.c> ExpiresActive Off </IfModule>
Note: After adding these lines to the .htaccess file, please clear browser cache from “all -time”.
These are the lines above, would definitely rescue you in this situation and instantly.
All the best and enjoy.