{"id":2635,"date":"2022-09-29T09:50:41","date_gmt":"2022-09-29T09:50:41","guid":{"rendered":"https:\/\/tronsdev.com\/tronsit.au\/?p=1702"},"modified":"2022-09-29T09:50:41","modified_gmt":"2022-09-29T09:50:41","slug":"how-to-leverage-browser-caching-in-wordpress","status":"publish","type":"post","link":"https:\/\/tronsdev.com\/tronsit\/how-to-leverage-browser-caching-in-wordpress\/","title":{"rendered":"How to Leverage Browser Caching in WordPress"},"content":{"rendered":"<p>Websites with a longer load time tend to have greater bounce rate, the reason being poor user experience. Users today prefer faster websites that load within 3-5 seconds. Page speed is a vital parameter to analyse a website\u2019s loading speed and search engine optimisation. Search engines successfully crawl into web pages that load faster than those which lack speed. Hence, to make your website rank in SERPs you must improve your website\u2019s page speed.<br \/>\nBesides <a href=\"https:\/\/tronsit.com\/gzip-compression-in-wordpress\/\" target=\"_blank\" rel=\"noopener noreferrer\">enabling GZIP Compression<\/a> on your WordPress website, you must work on to leverage browser caching to make your website load faster. To optimise page speed, such practices can create a dramatic difference.<\/p>\n<h3>How to Leverage Browser Caching in WordPress?<\/h3>\n<p>Following instructions can successfully enable browser caching for a WordPress website.<\/p>\n<ul>\n<li>\n<h3>Access .htaccess file<\/h3>\n<\/li>\n<\/ul>\n<p>To enable browser caching in WordPress, the .htaccess file needs to be edited. To locate . htaccesss file you need to use access cPanel or use File Transfer Protocol (FTP). This file is found in the root directory and is often hidden; hence you need to force hidden files to show.<\/p>\n<ul>\n<li>\n<h3>Edit .htaccess file<\/h3>\n<\/li>\n<\/ul>\n<p>By editing the .htaccess file of a WordPress you can adjust expiry dates of cacheable resources mentioned above. Enable the following changes in the .htaccess file to successfully enable leverage browser caching:<\/p>\n<h4>1. Add Expiry Headers with longer expiry dates<\/h4>\n<p>Adjust expiry dates according to your needs by modifying code present in the .htaccess file. You can boost site performance by changing expire headers. The following code modification is done keeping in mind the average time after which changes are made to HTML, CSS and JS elements of a WordPress site. The code also suggests how much time shall a browser take to expire the JPEG, GIF and PNG elements of a website.<\/p>\n<pre>FileETag MTime Size\nAddOutputFilterByType DEFLATE text\/plain text\/html text\/xml text\/css application\/xml application\/xhtml+xml application\/rss+xml application\/javascript application\/x-javascript\nExpiresActive On\nExpiresByType text\/html \"access 600 seconds\"\nExpiresByType application\/xhtml+xml \"access 600 seconds\"\nExpiresByType text\/css \"access 1 month\"\nExpiresByType text\/javascript \"access 1 month\"\nExpiresByType text\/x-javascript \"access 1 month\"\nExpiresByType application\/javascript \"access 1 month\"\nExpiresByType application\/x-javascript \"access 1 month\"\nExpiresByType application\/x-shockwave-flash \"access 1 month\"\nExpiresByType application\/pdf \"access 1 month\"\nExpiresByType image\/x-icon \"access 1 year\"\nExpiresByType image\/jpg \"access 1 year\"\nExpiresByType image\/jpeg \"access 1 year\"\nExpiresByType image\/png \"access 1 year\"\nExpiresByType image\/gif \"access 1 year\"\nExpiresDefault \"access 1 month\"\n\n#Expires cache end<\/pre>\n<h4>2. Add Cache-Control Header<\/h4>\n<p>Under the above-mentioned code add the following to specify Cache-Control Headers.<\/p>\n<pre># BEGIN Cache-Control Headers\n\n&lt;filesMatch \"\\.(ico|jpe?g|png|gif|swf)$\"&gt;\nHeader append Cache-Control \"public\"\n\n&lt;filesMatch \"\\.(css)$\"&gt;\nHeader append Cache-Control \"public\"\n\n&lt;filesMatch \"\\.(js)$\"&gt;\nHeader append Cache-Control \"private\"\n\n&lt;filesMatch \"\\.(x?html?|php)$\"&gt;\nHeader append Cache-Control \"private, must-revalidate\"<\/pre>\n<h4>3. Unset ETag Headers<\/h4>\n<p>ETags are entity tags are a mechanism that web servers and browsers use to analyse if the component in the browser&#8217;s cache matches the original server. One of the best practices includes to unsetting ETags especially if your website is using multiple servers or CDN. Add the following code to your .htaccess file to unset ETags.<\/p>\n<pre># Disable ETags\n\nHeader unset ETag\n\nFileETag None<\/pre>\n<ul>\n<li>\n<h3>Save and Run<\/h3>\n<\/li>\n<\/ul>\n<p>Save the changes on your .htaccess file and run the page speed tests to make sure that you have successfully enabled browser caching on WordPress Website.<\/p>\n<h3>Enabling Leverage Browser Caching on WordPress with a Plugin.<\/h3>\n<p>Browser Caching is a critical practice especially when you do not want to take any risks with your WordPress website. To make your work easy, WordPress offers multiple compatible plugins that enable browser caching for your website.<br \/>\nOne of the fastest and most recommended plugin that WordPress offers is WP Rocket. It dramatically speeds up your website by enabling multiple speed optimisation practices. WP Rocket\u2019s dynamic features also include:<br \/>\nGZIP Compression<br \/>\nGoogle Fonts Optimisation<br \/>\nLazy Loading<br \/>\nMinifying code<br \/>\nEnabling CDN<br \/>\nDNS prefetching<br \/>\nHope this article was much of a help! Boost your website speed and gain even better leads. Want to share something? Be part of the conversation, comment below!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Websites with a longer load time tend to have greater bounce rate, the reason being poor user experience. Users today prefer faster websites that load within 3-5 seconds. Page speed is a vital parameter to analyse a website\u2019s loading speed and search engine optimisation. Search engines successfully crawl into web pages that load faster than &#8230; <a title=\"How to Leverage Browser Caching in WordPress\" class=\"read-more\" href=\"https:\/\/tronsdev.com\/tronsit\/how-to-leverage-browser-caching-in-wordpress\/\" aria-label=\"Read more about How to Leverage Browser Caching in WordPress\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":2754,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[27],"tags":[26],"class_list":["post-2635","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-website-development","tag-website-development"],"_links":{"self":[{"href":"https:\/\/tronsdev.com\/tronsit\/wp-json\/wp\/v2\/posts\/2635","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/tronsdev.com\/tronsit\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/tronsdev.com\/tronsit\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/tronsdev.com\/tronsit\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/tronsdev.com\/tronsit\/wp-json\/wp\/v2\/comments?post=2635"}],"version-history":[{"count":0,"href":"https:\/\/tronsdev.com\/tronsit\/wp-json\/wp\/v2\/posts\/2635\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/tronsdev.com\/tronsit\/wp-json\/wp\/v2\/media\/2754"}],"wp:attachment":[{"href":"https:\/\/tronsdev.com\/tronsit\/wp-json\/wp\/v2\/media?parent=2635"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tronsdev.com\/tronsit\/wp-json\/wp\/v2\/categories?post=2635"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tronsdev.com\/tronsit\/wp-json\/wp\/v2\/tags?post=2635"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}