{"id":104,"date":"2011-12-25T13:09:00","date_gmt":"2011-12-25T13:09:00","guid":{"rendered":"http:\/\/pheonixsolutions.com\/?p=104"},"modified":"2026-05-31T09:32:07","modified_gmt":"2026-05-31T04:02:07","slug":"increase-the-access-speed-of-the-site-using-htaccess-cache","status":"publish","type":"post","link":"https:\/\/pheonixsolutions.com\/blog\/increase-the-access-speed-of-the-site-using-htaccess-cache\/","title":{"rendered":"Improve Website Performance Using .htaccess Browser Caching"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">Introduction<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Website performance plays a crucial role in user experience, search engine rankings, and overall server efficiency. One of the easiest ways to improve page load times is by enabling browser caching and content compression through the <code>.htaccess<\/code> file.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">When the Apache modules <strong>mod_expires<\/strong> and <strong>mod_headers<\/strong> are enabled on the server, you can configure caching rules that allow browsers to store static resources locally. This reduces the number of requests sent to the server and significantly improves website loading speeds for returning visitors.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Prerequisites<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Before implementing browser caching, ensure the following requirements are met:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Apache web server is in use.<\/li>\n\n\n\n<li>The <strong>mod_expires<\/strong> module is enabled.<\/li>\n\n\n\n<li>The <strong>mod_headers<\/strong> module is enabled.<\/li>\n\n\n\n<li>Access to the website&#8217;s <code>.htaccess<\/code> file.<\/li>\n\n\n\n<li>Appropriate backup of the existing <code>.htaccess<\/code> configuration before making changes.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">You can verify that the required modules are enabled by running:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">apachectl -M | grep -E 'expires|headers'\n<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Implementation<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Add the following directives to your website&#8217;s <code>.htaccess<\/code> file:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\"># BEGIN Compress Text Files\n\n&lt;IfModule mod_deflate.c>\n    SetOutputFilter DEFLATE\n&lt;\/IfModule>\n\n# END Compress Text Files\n\n# BEGIN Expire Headers\n\n&lt;IfModule mod_expires.c>\n    ExpiresActive On\n    ExpiresDefault \"access plus 1 seconds\"\n\n    ExpiresByType image\/x-icon \"access plus 2592000 seconds\"\n    ExpiresByType image\/jpeg \"access plus 2592000 seconds\"\n    ExpiresByType image\/png \"access plus 2592000 seconds\"\n    ExpiresByType image\/gif \"access plus 2592000 seconds\"\n    ExpiresByType application\/x-shockwave-flash \"access plus 2592000 seconds\"\n\n    ExpiresByType text\/css \"access plus 604800 seconds\"\n\n    ExpiresByType text\/javascript \"access plus 216000 seconds\"\n    ExpiresByType application\/javascript \"access plus 216000 seconds\"\n    ExpiresByType application\/x-javascript \"access plus 216000 seconds\"\n\n    ExpiresByType text\/html \"access plus 600 seconds\"\n    ExpiresByType application\/xhtml+xml \"access plus 600 seconds\"\n&lt;\/IfModule>\n\n# END Expire Headers\n\n# BEGIN Cache-Control Headers\n\n&lt;IfModule mod_headers.c>\n\n    &lt;FilesMatch \"\\.(ico|jpg|jpeg|png|gif|swf)$\">\n        Header set Cache-Control \"max-age=2592000, public\"\n    &lt;\/FilesMatch>\n\n    &lt;FilesMatch \"\\.(css)$\">\n        Header set Cache-Control \"max-age=604800, public\"\n    &lt;\/FilesMatch>\n\n    &lt;FilesMatch \"\\.(js)$\">\n        Header set Cache-Control \"max-age=216000, private\"\n    &lt;\/FilesMatch>\n\n    &lt;FilesMatch \"\\.(html|htm)$\">\n        Header set Cache-Control \"max-age=600, private, must-revalidate\"\n    &lt;\/FilesMatch>\n\n&lt;\/IfModule>\n\n# END Cache-Control Headers\n\n# BEGIN Disable ETags\n\n&lt;IfModule mod_headers.c>\n    Header unset ETag\n&lt;\/IfModule>\n\nFileETag None\n\n# END Disable ETags\n\n# BEGIN Remove Last-Modified Header\n\n&lt;IfModule mod_headers.c>\n    Header unset Last-Modified\n&lt;\/IfModule>\n\n# END Remove Last-Modified Header\n<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">How It Works<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">Compression (mod_deflate)<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The <code>DEFLATE<\/code> filter compresses text-based content before it is sent to visitors, reducing bandwidth usage and improving page load times.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Expires Headers<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Expires headers tell browsers how long they can store specific file types locally before requesting an updated version from the server.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Cache-Control Headers<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Cache-Control directives provide additional caching instructions for browsers and intermediary proxies, helping optimize content delivery.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">ETags<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Disabling ETags can reduce unnecessary validation requests and improve caching consistency, especially in load-balanced environments.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Last-Modified Header<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Removing the <code>Last-Modified<\/code> header can reduce conditional requests when expiration and cache-control directives are already being used.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Verification<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">After updating the <code>.htaccess<\/code> file:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Clear your browser cache.<\/li>\n\n\n\n<li>Reload the website.<\/li>\n\n\n\n<li>Use browser developer tools (Network tab) to verify caching headers.<\/li>\n\n\n\n<li>Test the website using performance tools such as:\n<ul class=\"wp-block-list\">\n<li>Google PageSpeed Insights<\/li>\n\n\n\n<li>GTmetrix<\/li>\n\n\n\n<li>WebPageTest<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Enabling browser caching and compression through <code>.htaccess<\/code> is a simple yet effective way to improve website performance. By leveraging Apache&#8217;s <code>mod_expires<\/code>, <code>mod_headers<\/code>, and <code>mod_deflate<\/code> modules, static resources can be cached efficiently, reducing server load and delivering faster page load times for visitors. Properly configured caching can significantly enhance user experience and contribute to better website performance overall.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction Website performance plays a crucial role in user experience, search engine rankings, and overall server efficiency. One of the [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[1024],"tags":[],"class_list":["post-104","post","type-post","status-publish","format-standard","hentry","category-security","psol-cat-security"],"jetpack_publicize_connections":[],"jetpack_shortlink":"https:\/\/wp.me\/phn2x7-1G","jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/104","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/comments?post=104"}],"version-history":[{"count":2,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/104\/revisions"}],"predecessor-version":[{"id":10286,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/104\/revisions\/10286"}],"wp:attachment":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/media?parent=104"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/categories?post=104"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/tags?post=104"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}