{"id":35,"date":"2015-06-16T14:49:00","date_gmt":"2015-06-16T14:49:00","guid":{"rendered":"https:\/\/www.tech-and-dev.com\/blog\/2015\/06\/16\/how-to-cache-files-to-leverage-browser-caching-in-htaccess\/"},"modified":"2021-02-22T01:04:02","modified_gmt":"2021-02-22T01:04:02","slug":"how-to-cache-files-to-leverage-browser","status":"publish","type":"post","link":"https:\/\/www.tech-and-dev.com\/blog\/2015\/06\/how-to-cache-files-to-leverage-browser.html","title":{"rendered":"How To Cache Files to Leverage Browser Caching in htaccess"},"content":{"rendered":"<div dir=\"ltr\" style=\"text-align: left;\">\n<p>&nbsp;<\/p>\n<div style=\"clear: both; text-align: center;\"><a style=\"margin-left: 1em; margin-right: 1em;\" href=\"https:\/\/www.tech-and-dev.com\/blog\/wp-content\/uploads\/2021\/02\/browser-caching.jpg\"><img decoding=\"async\" title=\"Leverage Browser Caching\" src=\"https:\/\/www.tech-and-dev.com\/blog\/wp-content\/uploads\/2021\/02\/browser-caching.jpg\" alt=\"Leverage Browser Caching\" border=\"0\" \/><\/a><\/div>\n<p>&nbsp;<\/p>\n<div style=\"text-align: justify;\">\n<p>One of the most essential factors in improving page loading speed is by caching static files such as javascripts, css, fonts and images in the user&#8217;s browser.<\/p>\n<p>This has lately became important specially when webmasters were testing their page speed on Google insights and getting the following message:<\/p>\n<\/div>\n<p><a name=\"more\"><\/a><br \/>\n<i><b>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.<\/b><\/i><\/p>\n<p>&nbsp;<\/p>\n<div style=\"text-align: justify;\">In order to easily fix this, just modify the htaccess in your website&#8217;s root directory by adding the following:<\/div>\n<p>&nbsp;<\/p>\n<pre>&lt;IfModule mod_expires.c&gt;\r\n\u00a0\u00a0\u00a0 ExpiresActive On\r\n\u00a0\u00a0\u00a0 ExpiresByType text\/css A31536000\r\n\u00a0\u00a0\u00a0 ExpiresByType application\/x-javascript A31536000\r\n\u00a0\u00a0\u00a0 ExpiresByType application\/javascript A31536000\r\n\u00a0\u00a0\u00a0 ExpiresByType text\/javascript A31536000\r\n\u00a0\u00a0\u00a0 ExpiresByType text\/x-js A31536000\r\n\u00a0\u00a0\u00a0 ExpiresByType text\/html A3600\r\n\u00a0\u00a0\u00a0 ExpiresByType text\/richtext A3600\r\n\u00a0\u00a0\u00a0 ExpiresByType image\/svg+xml A3600\r\n\u00a0\u00a0\u00a0 ExpiresByType text\/xsl A3600\r\n\u00a0\u00a0\u00a0 ExpiresByType text\/xml A3600\r\n\u00a0\u00a0\u00a0 ExpiresByType image\/bmp A31536000\r\n\u00a0\u00a0\u00a0 ExpiresByType image\/gif A31536000\r\n\u00a0\u00a0\u00a0 ExpiresByType image\/jpeg A31536000\r\n\u00a0\u00a0\u00a0 ExpiresByType application\/x-font-otf A31536000\r\n\u00a0\u00a0\u00a0 ExpiresByType application\/pdf A31536000\r\n\u00a0\u00a0\u00a0 ExpiresByType image\/png A31536000\r\n\u00a0\u00a0\u00a0 ExpiresByType application\/vnd.ms-powerpoint A31536000\r\n\u00a0\u00a0\u00a0 ExpiresByType audio\/x-realaudio A31536000\r\n\u00a0\u00a0\u00a0 ExpiresByType image\/svg+xml A31536000\r\n\u00a0\u00a0\u00a0 ExpiresByType image\/tiff A31536000\r\n\u00a0\u00a0\u00a0 ExpiresByType application\/x-font-ttf A31536000\r\n\u00a0\u00a0\u00a0 ExpiresByType application\/x-font-woff A31536000\r\n\u00a0\u00a0\u00a0 ExpiresByType application\/zip A31536000\r\n&lt;\/IfModule&gt;\r\n<\/pre>\n<p>This will cache most of the important static files. Feel free to add anything you want.<br \/>\n31536000 means caching will be done for 365 days while 3600 is for one hour.<\/p>\n<p><b>Any questions? Please comment below!<\/b><\/p>\n<p>&nbsp;<\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; &nbsp; One of the most essential factors in improving page loading speed is by caching static files such as javascripts, css, fonts and images in the user&#8217;s browser. This has lately became important specially when webmasters were testing their page speed on Google insights and getting the following message: Setting an expiry date or [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[48,47,49,40],"tags":[],"class_list":["post-35","post","type-post","status-publish","format-standard","hentry","category-apache","category-browsing","category-google","category-htaccess"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.tech-and-dev.com\/blog\/wp-json\/wp\/v2\/posts\/35","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.tech-and-dev.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tech-and-dev.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tech-and-dev.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tech-and-dev.com\/blog\/wp-json\/wp\/v2\/comments?post=35"}],"version-history":[{"count":1,"href":"https:\/\/www.tech-and-dev.com\/blog\/wp-json\/wp\/v2\/posts\/35\/revisions"}],"predecessor-version":[{"id":316,"href":"https:\/\/www.tech-and-dev.com\/blog\/wp-json\/wp\/v2\/posts\/35\/revisions\/316"}],"wp:attachment":[{"href":"https:\/\/www.tech-and-dev.com\/blog\/wp-json\/wp\/v2\/media?parent=35"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tech-and-dev.com\/blog\/wp-json\/wp\/v2\/categories?post=35"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tech-and-dev.com\/blog\/wp-json\/wp\/v2\/tags?post=35"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}