{"id":571,"date":"2011-02-28T04:07:08","date_gmt":"2011-02-28T11:07:08","guid":{"rendered":"https:\/\/wordpress-1325650-4848760.cloudwaysapps.com\/?p=571"},"modified":"2025-05-19T13:38:50","modified_gmt":"2025-05-19T17:38:50","slug":"mod_pagespeed-htaccess-tutorial","status":"publish","type":"post","link":"https:\/\/codesamplez.com\/devops\/mod_pagespeed-htaccess-tutorial","title":{"rendered":"Apache mod_pagespeed: Supercharge Your Website Speed"},"content":{"rendered":"\n<p>Have you ever wondered why some websites load blazingly fast while others crawl along like they&#8217;re stuck in digital quicksand? The secret often lies in how well the web server optimizes content delivery. That&#8217;s exactly where Apache mod_pagespeed comes in \u2013 it&#8217;s an absolute game-changer for website performance!<\/p>\n\n\n\n<p>I&#8217;ve been experimenting with mod_pagespeed for years now, and I&#8217;m absolutely blown away by how much it can improve website loading times with minimal effort. In this comprehensive guide, I&#8217;ll walk you through everything you need to know about implementing Apache mod_pagespeed using .htaccess configurations to dramatically boost your site&#8217;s performance.<\/p>\n\n\n\n<p><em>Tip \ud83d\udca1: If you are a complete beginner with .htaccess, consider the <a href=\"https:\/\/codesamplez.com\/devops\/apache-htaccess-basics\" target=\"_blank\" rel=\"noreferrer noopener\">htaccess for beginners guide<\/a>.<\/em><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What is Apache mod_pagespeed?<\/h2>\n\n\n\n<p>Apache mod_pagespeed is a powerful <a href=\"https:\/\/developers.google.com\/speed\/pagespeed\/module\" target=\"_blank\" rel=\"noreferrer noopener\">server module developed by Google<\/a> that automatically applies web performance best practices to pages and associated assets (CSS, JavaScript, images) without requiring you to modify your existing content or workflow. Originally announced by Google on their webmaster blog, this module has evolved to become one of the most effective ways to optimize website speed.<\/p>\n\n\n\n<p>The magic of mod_pagespeed is that it works at the server level, applying optimizations before content even reaches the browser. This means visitors experience faster page loads without you having to manually optimize every resource on your site.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Which Servers Support mod_pagespeed?<\/h2>\n\n\n\n<p>Before diving into implementation, let&#8217;s confirm whether your hosting environment supports mod_pagespeed:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Shared Hosting<\/strong>: Several major providers now support mod_pagespeed, including:\n<ul class=\"wp-block-list\">\n<li>GoDaddy (Linux shared hosting plans)<\/li>\n\n\n\n<li>Dreamhost<\/li>\n\n\n\n<li>A2 Hosting<\/li>\n\n\n\n<li>SiteGround<\/li>\n\n\n\n<li>Many others have added support since this module&#8217;s popularity has grown<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>VPS\/Dedicated Servers<\/strong>: If you manage your own server, you can easily install mod_pagespeed yourself for complete control over the optimization process.<\/li>\n<\/ul>\n\n\n\n<p>Always check with your hosting provider about mod_pagespeed support if you&#8217;re on a shared hosting plan. The good news is that adoption has increased significantly since Google released this technology.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Basic .htaccess Structure for Using mod_pagespeed<\/h2>\n\n\n\n<p>To implement mod_pagespeed on your server, you&#8217;ll need to create or modify a .htaccess file in your hosting root directory. The fundamental structure looks like this:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-1\" data-shcb-language-name=\"HTML, XML\" data-shcb-language-slug=\"xml\"><span><code class=\"hljs language-xml\"><span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">IfModule<\/span> <span class=\"hljs-attr\">pagespeed_module<\/span>&gt;<\/span>\n    ModPagespeed on\n    # Your optimization filters and directives go here\n<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">IfModule<\/span>&gt;<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-1\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">HTML, XML<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">xml<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>This code block checks if the pagespeed_module is available on your server and enables it. The position of this code in your .htaccess file doesn&#8217;t matter (top or bottom), but make sure it&#8217;s not nested inside another module&#8217;s code block.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">The Most Powerful mod_pagespeed Filters<\/h2>\n\n\n\n<p>Let&#8217;s explore the most effective filters that will transform your website&#8217;s performance. I&#8217;ve personally tested these on multiple sites and can vouch for their incredible impact:<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">1. Extend Cache (<code>extend_cache<\/code>)<\/h3>\n\n\n\n<p>This filter is pure genius! It enhances browser caching by ensuring resources remain cached even if they move location on the server. It works by generating customized URLs for resources with a one-year TTL (Time To Live), keeping them consistently available in users&#8217; browser caches.<\/p>\n\n\n\n<p><strong>Before using &#8216;extend_cache&#8217; filter:<\/strong><\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-2\" data-shcb-language-name=\"HTML, XML\" data-shcb-language-slug=\"xml\"><span><code class=\"hljs language-xml\"><span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">img<\/span> <span class=\"hljs-attr\">src<\/span>=<span class=\"hljs-string\">\"images\/simple_image.jpg\"<\/span> \/&gt;<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-2\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">HTML, XML<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">xml<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p><strong>After using &#8216;extend_cache&#8217; filter:<\/strong><\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-3\" data-shcb-language-name=\"HTML, XML\" data-shcb-language-slug=\"xml\"><span><code class=\"hljs language-xml\"><span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">img<\/span> <span class=\"hljs-attr\">src<\/span>=<span class=\"hljs-string\">\"images\/simple_image.jpg.pagespeed.ce.xo4He3_gYf.jpg\"<\/span> \/&gt;<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-3\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">HTML, XML<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">xml<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>The magic here is that even if you reorganize your file structure, browsers that have already cached the resource will still use their cached version!<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">2. Combine CSS (<code>combine_css<\/code>)<\/h3>\n\n\n\n<p>This is a massive performance boost! The filter merges multiple CSS files into a single file, dramatically reducing HTTP requests. Fewer requests mean faster page loads \u2013 it&#8217;s that simple.<\/p>\n\n\n\n<p><strong>Before using &#8216;combine_css&#8217;:<\/strong><\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-4\" data-shcb-language-name=\"HTML, XML\" data-shcb-language-slug=\"xml\"><span><code class=\"hljs language-xml\"><span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">link<\/span> <span class=\"hljs-attr\">rel<\/span>=<span class=\"hljs-string\">\"stylesheet\"<\/span> <span class=\"hljs-attr\">type<\/span>=<span class=\"hljs-string\">\"text\/css\"<\/span> <span class=\"hljs-attr\">href<\/span>=<span class=\"hljs-string\">\"styles\/main.css\"<\/span>&gt;<\/span>\n<span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">link<\/span> <span class=\"hljs-attr\">rel<\/span>=<span class=\"hljs-string\">\"stylesheet\"<\/span> <span class=\"hljs-attr\">type<\/span>=<span class=\"hljs-string\">\"text\/css\"<\/span> <span class=\"hljs-attr\">href<\/span>=<span class=\"hljs-string\">\"styles\/layout.css\"<\/span>&gt;<\/span>\n<span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">link<\/span> <span class=\"hljs-attr\">rel<\/span>=<span class=\"hljs-string\">\"stylesheet\"<\/span> <span class=\"hljs-attr\">type<\/span>=<span class=\"hljs-string\">\"text\/css\"<\/span> <span class=\"hljs-attr\">href<\/span>=<span class=\"hljs-string\">\"styles\/styles.css\"<\/span>&gt;<\/span>\n<span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">link<\/span> <span class=\"hljs-attr\">rel<\/span>=<span class=\"hljs-string\">\"stylesheet\"<\/span> <span class=\"hljs-attr\">type<\/span>=<span class=\"hljs-string\">\"text\/css\"<\/span> <span class=\"hljs-attr\">href<\/span>=<span class=\"hljs-string\">\"styles\/plugins.css\"<\/span>&gt;<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-4\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">HTML, XML<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">xml<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p><strong>After using &#8216;combine_css&#8217;:<\/strong><\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-5\" data-shcb-language-name=\"HTML, XML\" data-shcb-language-slug=\"xml\"><span><code class=\"hljs language-xml\"><span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">link<\/span> <span class=\"hljs-attr\">rel<\/span>=<span class=\"hljs-string\">\"stylesheet\"<\/span> <span class=\"hljs-attr\">type<\/span>=<span class=\"hljs-string\">\"text\/css\"<\/span> <span class=\"hljs-attr\">href<\/span>=<span class=\"hljs-string\">\"styles\/main.css+layout.css+styles.css+plugins.css.pagespeed.cc.xo4He3_gYf.css\"<\/span>&gt;<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-5\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">HTML, XML<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">xml<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>With modern websites often using dozens of CSS files, this consolidation creates a night-and-day difference in loading speed!<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">3. Collapse Whitespace (<code>collapse_whitespace<\/code>)<\/h3>\n\n\n\n<p>Don&#8217;t underestimate this seemingly simple optimization. By removing unnecessary whitespace from your HTML, this filter reduces file size and transfer time between server and browser.<\/p>\n\n\n\n<p><strong>Before using &#8216;collapse_whitespace&#8217;:<\/strong><\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-6\" data-shcb-language-name=\"HTML, XML\" data-shcb-language-slug=\"xml\"><span><code class=\"hljs language-xml\"><span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">head<\/span>&gt;<\/span>\n    <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">em<\/span>&gt;<\/span><span class=\"hljs-comment\">&lt;!-- head codes--&gt;<\/span><span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">em<\/span>&gt;<\/span>\n<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">head<\/span>&gt;<\/span>\n\n<span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">body<\/span>&gt;<\/span>\n    Simple texts\n<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">body<\/span>&gt;<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-6\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">HTML, XML<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">xml<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p><strong>After using &#8216;collapse_whitespace&#8217;:<\/strong><\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-7\" data-shcb-language-name=\"HTML, XML\" data-shcb-language-slug=\"xml\"><span><code class=\"hljs language-xml\"><span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">head<\/span>&gt;<\/span><span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">em<\/span>&gt;<\/span><span class=\"hljs-comment\">&lt;!-- head codes--&gt;<\/span><span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">em<\/span>&gt;<\/span><span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">head<\/span>&gt;<\/span><span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">body<\/span>&gt;<\/span>Simple texts<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">body<\/span>&gt;<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-7\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">HTML, XML<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">xml<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>While the difference looks minor in this example, across an entire website with thousands of lines of HTML, the reduction in file size adds up significantly!<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">4. Move CSS to HEAD (<code>move_css_to_head<\/code>)<\/h3>\n\n\n\n<p>This filter automatically moves all CSS references into the document&#8217;s <code>&lt;head&gt;<\/code> section, following web performance best practices. This is particularly valuable for WordPress sites where plugins often inject CSS in suboptimal locations.<\/p>\n\n\n\n<p><strong>Before using &#8216;move_css_to_head&#8217;:<\/strong><\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-8\" data-shcb-language-name=\"HTML, XML\" data-shcb-language-slug=\"xml\"><span><code class=\"hljs language-xml\"><span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">html<\/span>&gt;<\/span>\n<span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">head<\/span>&gt;<\/span>\n<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">head<\/span>&gt;<\/span>\n<span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">body<\/span>&gt;<\/span>\n    <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">div<\/span> <span class=\"hljs-attr\">class<\/span>=<span class=\"hljs-string\">\"blue yellow big bold\"<\/span>&gt;<\/span>\n        Simple Html Example\n    <span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">div<\/span>&gt;<\/span>\n    <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">link<\/span> <span class=\"hljs-attr\">rel<\/span>=<span class=\"hljs-string\">\"stylesheet\"<\/span> <span class=\"hljs-attr\">type<\/span>=<span class=\"hljs-string\">\"text\/css\"<\/span> <span class=\"hljs-attr\">href<\/span>=<span class=\"hljs-string\">\"css\/style.css\"<\/span>&gt;<\/span>\n<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">body<\/span>&gt;<\/span>\n<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">html<\/span>&gt;<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-8\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">HTML, XML<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">xml<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p><strong>After using &#8216;move_css_to_head&#8217;:<\/strong><\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-9\" data-shcb-language-name=\"HTML, XML\" data-shcb-language-slug=\"xml\"><span><code class=\"hljs language-xml\"><span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">html<\/span>&gt;<\/span>\n<span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">head<\/span>&gt;<\/span>\n    <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">link<\/span> <span class=\"hljs-attr\">rel<\/span>=<span class=\"hljs-string\">\"stylesheet\"<\/span> <span class=\"hljs-attr\">type<\/span>=<span class=\"hljs-string\">\"text\/css\"<\/span> <span class=\"hljs-attr\">href<\/span>=<span class=\"hljs-string\">\"css\/style.css\"<\/span>&gt;<\/span>\n<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">head<\/span>&gt;<\/span>\n<span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">body<\/span>&gt;<\/span>\n    <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">div<\/span> <span class=\"hljs-attr\">class<\/span>=<span class=\"hljs-string\">\"blue yellow big bold\"<\/span>&gt;<\/span>\n        Simple Html Example\n    <span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">div<\/span>&gt;<\/span>\n<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">body<\/span>&gt;<\/span>\n<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">html<\/span>&gt;<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-9\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">HTML, XML<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">xml<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>This optimization prevents render-blocking issues where the browser has to stop and recalculate styles after content has already begun loading.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">5. Remove Comments (<code>remove_comments<\/code>)<\/h3>\n\n\n\n<p>This filter strips unnecessary HTML comments, reducing file size without affecting functionality. Importantly, it&#8217;s smart enough to preserve critical comments like Internet Explorer conditional statements.<\/p>\n\n\n\n<p><strong>Before using &#8216;remove_comments&#8217;:<\/strong><\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-10\" data-shcb-language-name=\"HTML, XML\" data-shcb-language-slug=\"xml\"><span><code class=\"hljs language-xml\"><span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">link<\/span> <span class=\"hljs-attr\">rel<\/span>=<span class=\"hljs-string\">'shortlink'<\/span> <span class=\"hljs-attr\">href<\/span>=<span class=\"hljs-string\">'http:\/\/wp.me\/1hHlI'<\/span> \/&gt;<\/span>\n<span class=\"hljs-comment\">&lt;!-- This comment explains the following code --&gt;<\/span>\n<span class=\"hljs-comment\">&lt;!--&#91;if IE]&gt;\n&lt;style type=\"text\/css\"&gt;\n.addtoany_list a img{filter:alpha(opacity=70)}\n.addtoany_list a:hover img,.addtoany_list a.addtoany_share_save img{filter:alpha(opacity=100)}\n&lt;\/style&gt;\n&lt;!&#91;endif]--&gt;<\/span>\n<span class=\"hljs-comment\">&lt;!-- All in One SEO Pack 2.15.0 by Michael Torbert --&gt;<\/span>\n<span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">meta<\/span> <span class=\"hljs-attr\">name<\/span>=<span class=\"hljs-string\">\"description\"<\/span> <span class=\"hljs-attr\">content<\/span>=<span class=\"hljs-string\">\"website description\"<\/span> \/&gt;<\/span>\n<span class=\"hljs-comment\">&lt;!-- \/all in one seo pack --&gt;<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-10\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">HTML, XML<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">xml<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p><strong>After using &#8216;remove_comments&#8217;:<\/strong><\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-11\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\">&lt;link rel=<span class=\"hljs-string\">'shortlink'<\/span> href=<span class=\"hljs-string\">'http:\/\/wp.me\/1hHlI'<\/span> \/&gt;\n&lt;!--&#91;<span class=\"hljs-keyword\">if<\/span> IE]&gt;\n<span class=\"xml\"><span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">style<\/span> <span class=\"hljs-attr\">type<\/span>=<span class=\"hljs-string\">\"text\/css\"<\/span>&gt;<\/span><span class=\"css\">\n<span class=\"hljs-selector-class\">.addtoany_list<\/span> <span class=\"hljs-selector-tag\">a<\/span> <span class=\"hljs-selector-tag\">img<\/span>{<span class=\"hljs-attribute\">filter<\/span>:<span class=\"hljs-built_in\">alpha<\/span>(opacity=<span class=\"hljs-number\">70<\/span>)}\n<span class=\"hljs-selector-class\">.addtoany_list<\/span> <span class=\"hljs-selector-tag\">a<\/span><span class=\"hljs-selector-pseudo\">:hover<\/span> <span class=\"hljs-selector-tag\">img<\/span>,<span class=\"hljs-selector-class\">.addtoany_list<\/span> <span class=\"hljs-selector-tag\">a<\/span><span class=\"hljs-selector-class\">.addtoany_share_save<\/span> <span class=\"hljs-selector-tag\">img<\/span>{<span class=\"hljs-attribute\">filter<\/span>:<span class=\"hljs-built_in\">alpha<\/span>(opacity=<span class=\"hljs-number\">100<\/span>)}\n<\/span><span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">style<\/span>&gt;<\/span><\/span>\n&lt;!&#91;endif]--&gt;\n<span class=\"xml\"><span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">meta<\/span> <span class=\"hljs-attr\">name<\/span>=<span class=\"hljs-string\">\"description\"<\/span> <span class=\"hljs-attr\">content<\/span>=<span class=\"hljs-string\">\"website description\"<\/span> \/&gt;<\/span><\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-11\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Notice how it intelligently preserves the IE conditional comment while removing the unnecessary explanatory comments.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Additional Powerful Filters Worth Implementing<\/h3>\n\n\n\n<p>While I&#8217;ve covered the essential filters above, here are some additional options that can further enhance your site&#8217;s performance:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Combine JavaScript (<code>combine_javascript<\/code>)<\/strong>: Similar to combine_css, this merges JavaScript files to reduce HTTP requests.<\/li>\n\n\n\n<li><strong>Inline CSS (<code>inline_css<\/code>)<\/strong>: Embeds small CSS files directly into HTML, eliminating separate requests.<\/li>\n\n\n\n<li><strong>Optimize Images (<code>rewrite_images<\/code>)<\/strong>: Automatically optimizes image files without quality loss.<\/li>\n\n\n\n<li><strong>Defer JavaScript (<code>defer_javascript<\/code>)<\/strong>: Delays JavaScript execution until after page load.<\/li>\n\n\n\n<li><strong>Minify JavaScript (<code>rewrite_javascript<\/code>)<\/strong>: Removes unnecessary characters from JavaScript files.<\/li>\n\n\n\n<li><strong>Minify CSS (<code>rewrite_css<\/code>)<\/strong>: Strips whitespace and unnecessary characters from CSS files.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Essential .htaccess Directives for Fine-Tuning<\/h2>\n\n\n\n<p>Beyond filters, mod_pagespeed offers powerful directives that give you precise control over how optimization happens. Here are two that I&#8217;ve found particularly useful:<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">1. Restrict Files from Being Rewritten (<code>ModPagespeedDisallow<\/code>)<\/h3>\n\n\n\n<p>Some files shouldn&#8217;t be modified, particularly sensitive JavaScript libraries that depend on specific formatting or naming. You can exclude these files using:<\/p>\n\n\n<pre class=\"wp-block-code\"><span><code class=\"hljs\">ModPagespeedDisallow *\/jquery-ui-1.8.2.custom.min.js<\/code><\/span><\/pre>\n\n\n<p>This prevents mod_pagespeed from modifying your jQuery UI files, which can sometimes break when optimized.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">2. Specify Files to Be Rewritten (<code>ModPagespeedAllow<\/code>)<\/h3>\n\n\n\n<p>When you want to limit optimization to specific files rather than applying it broadly, use:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-12\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\">ModPagespeedDisallow *\nModPagespeedAllow http:<span class=\"hljs-comment\">\/\/*mydomain.com\/*\/css\/*.css<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-12\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>This configuration will only optimize CSS files while leaving everything else untouched \u2013 perfect for selectively applying optimizations during testing.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Ready-to-Use .htaccess Configuration<\/h2>\n\n\n\n<p>Ready to implement mod_pagespeed? Here&#8217;s a production-ready configuration you can copy directly into your .htaccess file:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-13\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\">&lt;IfModule pagespeed_module&gt;\n    <span class=\"hljs-comment\"># Enable PageSpeed<\/span>\n    ModPagespeed on\n    \n    <span class=\"hljs-comment\"># Core optimization filters<\/span>\n    ModPagespeedEnableFilters extend_cache,combine_css,collapse_whitespace,move_css_to_head,remove_comments\n    \n    <span class=\"hljs-comment\"># Additional recommended filters<\/span>\n    ModPagespeedEnableFilters combine_javascript,rewrite_images,inline_css,defer_javascript\n    \n    <span class=\"hljs-comment\"># Prevent optimization of specific files if needed<\/span>\n    <span class=\"hljs-comment\"># ModPagespeedDisallow *\/jquery*.js<\/span>\n    \n    <span class=\"hljs-comment\"># Increase cache lifetime for pagespeed resources<\/span>\n    ModPagespeedFileCachePath <span class=\"hljs-string\">\"\/var\/cache\/mod_pagespeed\/\"<\/span>\n    ModPagespeedFileCacheSizeKb <span class=\"hljs-number\">102400<\/span>\n    ModPagespeedFileCacheInodeLimit <span class=\"hljs-number\">500000<\/span>\n&lt;\/IfModule&gt;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-13\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>This configuration provides an excellent starting point that balances aggressive optimization with compatibility. It&#8217;s specifically tested to work well on GoDaddy and similar shared hosting environments.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Measuring Performance Improvements<\/h2>\n\n\n\n<p>After implementing mod_pagespeed, you&#8217;ll want to quantify the performance gains. Here are the best tools for measuring your site&#8217;s speed improvement:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong><a href=\"https:\/\/pagespeed.web.dev\/\" target=\"_blank\" rel=\"noreferrer noopener\">Google PageSpeed Insights<\/a><\/strong>: Google&#8217;s official tool provides before-and-after scores and specific recommendations.<\/li>\n\n\n\n<li><strong><a href=\"https:\/\/www.webpagetest.org\/\" target=\"_blank\" rel=\"noreferrer noopener\">WebPageTest.org<\/a><\/strong>: Offers detailed waterfall charts showing loading times for each resource.<\/li>\n\n\n\n<li><strong><a href=\"https:\/\/gtmetrix.com\/\" target=\"_blank\" rel=\"noreferrer noopener\">GTmetrix<\/a><\/strong>: Combines multiple testing tools and provides comprehensive reports.<\/li>\n\n\n\n<li><strong><a href=\"https:\/\/chromewebstore.google.com\/detail\/lighthouse\/blipmdconlkpinefehnmjammfjpmpbjk?pli=1\" target=\"_blank\" rel=\"noreferrer noopener\">Lighthouse<\/a><\/strong>: Chrome&#8217;s built-in auditing tool (available in DevTools).<\/li>\n\n\n\n<li><strong><a href=\"https:\/\/support.google.com\/webmasters\/answer\/9205520?hl=en\" target=\"_blank\" rel=\"noreferrer noopener\">Core Web Vitals report<\/a><\/strong> in Google Search Console: Tracks real-world user experience metrics.<\/li>\n<\/ol>\n\n\n\n<p>I recommend running these tests before implementing mod_pagespeed and again afterward to see the dramatic difference. Don&#8217;t be surprised if your scores improve by 20-30 points or more!<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Troubleshooting Common Issues<\/h2>\n\n\n\n<p>While mod_pagespeed is generally reliable, you might encounter a few hiccups:<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">500 Server Errors<\/h3>\n\n\n\n<p>If you see a 500 error after adding mod_pagespeed directives, check for:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Syntax errors<\/strong>: Ensure there are no spaces between filter names in your ModPagespeedEnableFilters directive. <\/li>\n<\/ul>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-14\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\"><span class=\"hljs-comment\"># Correct (no spaces after commas) <\/span>\nModPagespeedEnableFilters extend_cache,combine_css,collapse_whitespace \n<span class=\"hljs-comment\"># Incorrect (spaces after commas) <\/span>\nModPagespeedEnableFilters extend_cache, combine_css, collapse_whitespace<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-14\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Module availability<\/strong>: Your hosting might not support all filters. Try enabling filters one by one to identify problematic ones.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">Visual Glitches<\/h3>\n\n\n\n<p>If your site looks different after enabling mod_pagespeed:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Disable the <code>combine_css<\/code> filter first to see if that resolves the issue.<\/li>\n\n\n\n<li>Check for CSS that relies on specific file ordering.<\/li>\n\n\n\n<li>Use ModPagespeedDisallow to exclude problematic files.<\/li>\n<\/ol>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p>Apache mod_pagespeed is one of the easiest yet most effective ways to dramatically improve your website&#8217;s loading speed. With the configurations provided in this guide, you can implement professional-level optimizations without having to manually modify your site&#8217;s code.<\/p>\n\n\n\n<p>Remember that website speed isn&#8217;t just about user experience \u2013 it&#8217;s also a significant ranking factor for search engines. By implementing mod_pagespeed, you&#8217;re not only making your visitors happier but potentially improving your search visibility as well.<\/p>\n\n\n\n<p>Have you implemented mod_pagespeed on your website? I&#8217;d love to hear about your experience in the comments below! And if you have any questions about optimizing your specific setup, feel free to ask \u2013 I&#8217;m always happy to help fellow performance enthusiasts.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This article introduces Google&#8217;s mod_pagespeed for Apache, explaining how to enable it via .htaccess to enhance website performance. It covers essential directives and filters, providing practical examples to help developers optimize their sites effectively. This guide is ideal for those new to mod_pagespeed or looking to improve their web optimization skills.<\/p>\n","protected":false},"author":1,"featured_media":58725,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_genesis_hide_title":false,"_genesis_hide_breadcrumbs":false,"_genesis_hide_singular_image":false,"_genesis_hide_footer_widgets":false,"_genesis_custom_body_class":"","_genesis_custom_post_class":"","_genesis_layout":"","jetpack_post_was_ever_published":false,"_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}},"categories":[32],"tags":[30,31],"class_list":{"0":"post-571","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-devops","8":"tag-apache","9":"tag-htaccess","10":"entry"},"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v27.3 (Yoast SEO v27.3) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Apache mod_pagespeed: Supercharge Your Website Speed - CodeSamplez.com<\/title>\n<meta name=\"description\" content=\"Learn how to supercharge your website speed with Apache mod_pagespeed using simple .htaccess configurations. Dramatically fasten page loads.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/codesamplez.com\/devops\/mod_pagespeed-htaccess-tutorial\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Apache mod_pagespeed: Supercharge Your Website Speed\" \/>\n<meta property=\"og:description\" content=\"Learn how to supercharge your website speed with Apache mod_pagespeed using simple .htaccess configurations. Dramatically fasten page loads.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/codesamplez.com\/devops\/mod_pagespeed-htaccess-tutorial\" \/>\n<meta property=\"og:site_name\" content=\"CodeSamplez.com\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/codesamplez\" \/>\n<meta property=\"article:author\" content=\"https:\/\/www.facebook.com\/ranacseruet\" \/>\n<meta property=\"article:published_time\" content=\"2011-02-28T11:07:08+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-05-19T17:38:50+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/codesamplez.com\/wp-content\/uploads\/2011\/02\/apache-mod_pagespeed.webp\" \/>\n\t<meta property=\"og:image:width\" content=\"1536\" \/>\n\t<meta property=\"og:image:height\" content=\"1024\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/webp\" \/>\n<meta name=\"author\" content=\"Rana Ahsan\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@ranacseruet\" \/>\n<meta name=\"twitter:site\" content=\"@codesamplez\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Rana Ahsan\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":[\"Article\",\"BlogPosting\"],\"@id\":\"https:\\\/\\\/codesamplez.com\\\/devops\\\/mod_pagespeed-htaccess-tutorial#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/codesamplez.com\\\/devops\\\/mod_pagespeed-htaccess-tutorial\"},\"author\":{\"name\":\"Rana Ahsan\",\"@id\":\"https:\\\/\\\/codesamplez.com\\\/#\\\/schema\\\/person\\\/a82c3c07205f4bb73d6b3b0906bc328b\"},\"headline\":\"Apache mod_pagespeed: Supercharge Your Website Speed\",\"datePublished\":\"2011-02-28T11:07:08+00:00\",\"dateModified\":\"2025-05-19T17:38:50+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/codesamplez.com\\\/devops\\\/mod_pagespeed-htaccess-tutorial\"},\"wordCount\":1361,\"commentCount\":4,\"publisher\":{\"@id\":\"https:\\\/\\\/codesamplez.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/codesamplez.com\\\/devops\\\/mod_pagespeed-htaccess-tutorial#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/codesamplez.com\\\/wp-content\\\/uploads\\\/2011\\\/02\\\/apache-mod_pagespeed.webp\",\"keywords\":[\"apache\",\"htaccess\"],\"articleSection\":[\"DevOps\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/codesamplez.com\\\/devops\\\/mod_pagespeed-htaccess-tutorial#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/codesamplez.com\\\/devops\\\/mod_pagespeed-htaccess-tutorial\",\"url\":\"https:\\\/\\\/codesamplez.com\\\/devops\\\/mod_pagespeed-htaccess-tutorial\",\"name\":\"Apache mod_pagespeed: Supercharge Your Website Speed - CodeSamplez.com\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/codesamplez.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/codesamplez.com\\\/devops\\\/mod_pagespeed-htaccess-tutorial#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/codesamplez.com\\\/devops\\\/mod_pagespeed-htaccess-tutorial#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/codesamplez.com\\\/wp-content\\\/uploads\\\/2011\\\/02\\\/apache-mod_pagespeed.webp\",\"datePublished\":\"2011-02-28T11:07:08+00:00\",\"dateModified\":\"2025-05-19T17:38:50+00:00\",\"description\":\"Learn how to supercharge your website speed with Apache mod_pagespeed using simple .htaccess configurations. Dramatically fasten page loads.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/codesamplez.com\\\/devops\\\/mod_pagespeed-htaccess-tutorial#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/codesamplez.com\\\/devops\\\/mod_pagespeed-htaccess-tutorial\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/codesamplez.com\\\/devops\\\/mod_pagespeed-htaccess-tutorial#primaryimage\",\"url\":\"https:\\\/\\\/codesamplez.com\\\/wp-content\\\/uploads\\\/2011\\\/02\\\/apache-mod_pagespeed.webp\",\"contentUrl\":\"https:\\\/\\\/codesamplez.com\\\/wp-content\\\/uploads\\\/2011\\\/02\\\/apache-mod_pagespeed.webp\",\"width\":1536,\"height\":1024,\"caption\":\"apache mod_pagespeed\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/codesamplez.com\\\/devops\\\/mod_pagespeed-htaccess-tutorial#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/codesamplez.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Apache mod_pagespeed: Supercharge Your Website Speed\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/codesamplez.com\\\/#website\",\"url\":\"https:\\\/\\\/codesamplez.com\\\/\",\"name\":\"CODESAMPLEZ.COM\",\"description\":\"Programming And Development Resources\",\"publisher\":{\"@id\":\"https:\\\/\\\/codesamplez.com\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/codesamplez.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/codesamplez.com\\\/#organization\",\"name\":\"codesamplez.com\",\"url\":\"https:\\\/\\\/codesamplez.com\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/codesamplez.com\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/codesamplez.com\\\/wp-content\\\/uploads\\\/2024\\\/10\\\/cropped-favicon.webp\",\"contentUrl\":\"https:\\\/\\\/codesamplez.com\\\/wp-content\\\/uploads\\\/2024\\\/10\\\/cropped-favicon.webp\",\"width\":512,\"height\":512,\"caption\":\"codesamplez.com\"},\"image\":{\"@id\":\"https:\\\/\\\/codesamplez.com\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/codesamplez\",\"https:\\\/\\\/x.com\\\/codesamplez\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/codesamplez.com\\\/#\\\/schema\\\/person\\\/a82c3c07205f4bb73d6b3b0906bc328b\",\"name\":\"Rana Ahsan\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/5c7a4f88bcf4a55cd1483386318ebecf27359154275a0b355b0ea186676f9f7f?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/5c7a4f88bcf4a55cd1483386318ebecf27359154275a0b355b0ea186676f9f7f?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/5c7a4f88bcf4a55cd1483386318ebecf27359154275a0b355b0ea186676f9f7f?s=96&d=mm&r=g\",\"caption\":\"Rana Ahsan\"},\"description\":\"Rana Ahsan is a seasoned software engineer and technology leader specialized in distributed systems and software architecture. With a Master\u2019s in Software Engineering from Concordia University, his experience spans leading scalable architecture at Coursera and TopHat, contributing to open-source projects. This blog, CodeSamplez.com, showcases his passion for sharing practical insights on programming and distributed systems concepts and help educate others. Github | X | LinkedIn\",\"sameAs\":[\"https:\\\/\\\/github.com\\\/ranacseruet\",\"https:\\\/\\\/www.facebook.com\\\/ranacseruet\",\"https:\\\/\\\/www.linkedin.com\\\/in\\\/ranacseruet\\\/\",\"https:\\\/\\\/x.com\\\/ranacseruet\"],\"url\":\"https:\\\/\\\/codesamplez.com\\\/author\\\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Apache mod_pagespeed: Supercharge Your Website Speed - CodeSamplez.com","description":"Learn how to supercharge your website speed with Apache mod_pagespeed using simple .htaccess configurations. Dramatically fasten page loads.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/codesamplez.com\/devops\/mod_pagespeed-htaccess-tutorial","og_locale":"en_US","og_type":"article","og_title":"Apache mod_pagespeed: Supercharge Your Website Speed","og_description":"Learn how to supercharge your website speed with Apache mod_pagespeed using simple .htaccess configurations. Dramatically fasten page loads.","og_url":"https:\/\/codesamplez.com\/devops\/mod_pagespeed-htaccess-tutorial","og_site_name":"CodeSamplez.com","article_publisher":"https:\/\/www.facebook.com\/codesamplez","article_author":"https:\/\/www.facebook.com\/ranacseruet","article_published_time":"2011-02-28T11:07:08+00:00","article_modified_time":"2025-05-19T17:38:50+00:00","og_image":[{"width":1536,"height":1024,"url":"https:\/\/codesamplez.com\/wp-content\/uploads\/2011\/02\/apache-mod_pagespeed.webp","type":"image\/webp"}],"author":"Rana Ahsan","twitter_card":"summary_large_image","twitter_creator":"@ranacseruet","twitter_site":"@codesamplez","twitter_misc":{"Written by":"Rana Ahsan","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":["Article","BlogPosting"],"@id":"https:\/\/codesamplez.com\/devops\/mod_pagespeed-htaccess-tutorial#article","isPartOf":{"@id":"https:\/\/codesamplez.com\/devops\/mod_pagespeed-htaccess-tutorial"},"author":{"name":"Rana Ahsan","@id":"https:\/\/codesamplez.com\/#\/schema\/person\/a82c3c07205f4bb73d6b3b0906bc328b"},"headline":"Apache mod_pagespeed: Supercharge Your Website Speed","datePublished":"2011-02-28T11:07:08+00:00","dateModified":"2025-05-19T17:38:50+00:00","mainEntityOfPage":{"@id":"https:\/\/codesamplez.com\/devops\/mod_pagespeed-htaccess-tutorial"},"wordCount":1361,"commentCount":4,"publisher":{"@id":"https:\/\/codesamplez.com\/#organization"},"image":{"@id":"https:\/\/codesamplez.com\/devops\/mod_pagespeed-htaccess-tutorial#primaryimage"},"thumbnailUrl":"https:\/\/codesamplez.com\/wp-content\/uploads\/2011\/02\/apache-mod_pagespeed.webp","keywords":["apache","htaccess"],"articleSection":["DevOps"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/codesamplez.com\/devops\/mod_pagespeed-htaccess-tutorial#respond"]}]},{"@type":"WebPage","@id":"https:\/\/codesamplez.com\/devops\/mod_pagespeed-htaccess-tutorial","url":"https:\/\/codesamplez.com\/devops\/mod_pagespeed-htaccess-tutorial","name":"Apache mod_pagespeed: Supercharge Your Website Speed - CodeSamplez.com","isPartOf":{"@id":"https:\/\/codesamplez.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/codesamplez.com\/devops\/mod_pagespeed-htaccess-tutorial#primaryimage"},"image":{"@id":"https:\/\/codesamplez.com\/devops\/mod_pagespeed-htaccess-tutorial#primaryimage"},"thumbnailUrl":"https:\/\/codesamplez.com\/wp-content\/uploads\/2011\/02\/apache-mod_pagespeed.webp","datePublished":"2011-02-28T11:07:08+00:00","dateModified":"2025-05-19T17:38:50+00:00","description":"Learn how to supercharge your website speed with Apache mod_pagespeed using simple .htaccess configurations. Dramatically fasten page loads.","breadcrumb":{"@id":"https:\/\/codesamplez.com\/devops\/mod_pagespeed-htaccess-tutorial#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/codesamplez.com\/devops\/mod_pagespeed-htaccess-tutorial"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/codesamplez.com\/devops\/mod_pagespeed-htaccess-tutorial#primaryimage","url":"https:\/\/codesamplez.com\/wp-content\/uploads\/2011\/02\/apache-mod_pagespeed.webp","contentUrl":"https:\/\/codesamplez.com\/wp-content\/uploads\/2011\/02\/apache-mod_pagespeed.webp","width":1536,"height":1024,"caption":"apache mod_pagespeed"},{"@type":"BreadcrumbList","@id":"https:\/\/codesamplez.com\/devops\/mod_pagespeed-htaccess-tutorial#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/codesamplez.com\/"},{"@type":"ListItem","position":2,"name":"Apache mod_pagespeed: Supercharge Your Website Speed"}]},{"@type":"WebSite","@id":"https:\/\/codesamplez.com\/#website","url":"https:\/\/codesamplez.com\/","name":"CODESAMPLEZ.COM","description":"Programming And Development Resources","publisher":{"@id":"https:\/\/codesamplez.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/codesamplez.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/codesamplez.com\/#organization","name":"codesamplez.com","url":"https:\/\/codesamplez.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/codesamplez.com\/#\/schema\/logo\/image\/","url":"https:\/\/codesamplez.com\/wp-content\/uploads\/2024\/10\/cropped-favicon.webp","contentUrl":"https:\/\/codesamplez.com\/wp-content\/uploads\/2024\/10\/cropped-favicon.webp","width":512,"height":512,"caption":"codesamplez.com"},"image":{"@id":"https:\/\/codesamplez.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/codesamplez","https:\/\/x.com\/codesamplez"]},{"@type":"Person","@id":"https:\/\/codesamplez.com\/#\/schema\/person\/a82c3c07205f4bb73d6b3b0906bc328b","name":"Rana Ahsan","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/5c7a4f88bcf4a55cd1483386318ebecf27359154275a0b355b0ea186676f9f7f?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/5c7a4f88bcf4a55cd1483386318ebecf27359154275a0b355b0ea186676f9f7f?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/5c7a4f88bcf4a55cd1483386318ebecf27359154275a0b355b0ea186676f9f7f?s=96&d=mm&r=g","caption":"Rana Ahsan"},"description":"Rana Ahsan is a seasoned software engineer and technology leader specialized in distributed systems and software architecture. With a Master\u2019s in Software Engineering from Concordia University, his experience spans leading scalable architecture at Coursera and TopHat, contributing to open-source projects. This blog, CodeSamplez.com, showcases his passion for sharing practical insights on programming and distributed systems concepts and help educate others. Github | X | LinkedIn","sameAs":["https:\/\/github.com\/ranacseruet","https:\/\/www.facebook.com\/ranacseruet","https:\/\/www.linkedin.com\/in\/ranacseruet\/","https:\/\/x.com\/ranacseruet"],"url":"https:\/\/codesamplez.com\/author\/admin"}]}},"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/codesamplez.com\/wp-content\/uploads\/2011\/02\/apache-mod_pagespeed.webp","jetpack_shortlink":"https:\/\/wp.me\/p1hHlI-9d","jetpack_sharing_enabled":true,"jetpack-related-posts":[{"id":464,"url":"https:\/\/codesamplez.com\/devops\/apache-htaccess-basics","url_meta":{"origin":571,"position":0},"title":"htaccess for Beginners: The Ultimate Guide","author":"Rana Ahsan","date":"February 17, 2011","format":false,"excerpt":"The article provides a concise introduction to .htaccess files for Apache servers. It covers essential topics such as URL rewriting, password protection, and access control, offering practical examples to help developers manage website configurations effectively. This guide is particularly useful for those new to .htaccess or seeking to enhance their\u2026","rel":"","context":"In &quot;DevOps&quot;","block_context":{"text":"DevOps","link":"https:\/\/codesamplez.com\/category\/devops"},"img":{"alt_text":"htaccess for beginners","src":"https:\/\/i0.wp.com\/codesamplez.com\/wp-content\/uploads\/2011\/02\/htaccess-for-beginners.webp?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/codesamplez.com\/wp-content\/uploads\/2011\/02\/htaccess-for-beginners.webp?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/codesamplez.com\/wp-content\/uploads\/2011\/02\/htaccess-for-beginners.webp?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/codesamplez.com\/wp-content\/uploads\/2011\/02\/htaccess-for-beginners.webp?resize=700%2C400&ssl=1 2x, https:\/\/i0.wp.com\/codesamplez.com\/wp-content\/uploads\/2011\/02\/htaccess-for-beginners.webp?resize=1050%2C600&ssl=1 3x, https:\/\/i0.wp.com\/codesamplez.com\/wp-content\/uploads\/2011\/02\/htaccess-for-beginners.webp?resize=1400%2C800&ssl=1 4x"},"classes":[]},{"id":22719,"url":"https:\/\/codesamplez.com\/devops\/lamp-stack-on-ubuntu","url_meta":{"origin":571,"position":1},"title":"Installing LAMP Stack on Ubuntu: The Ultimate Guide","author":"Rana Ahsan","date":"March 13, 2013","format":false,"excerpt":"This article provides a step-by-step guide to installing the LAMP stack\u2014Linux, Apache, MySQL, and PHP\u2014on an Ubuntu server. It emphasizes manual installation over bundled packages for greater flexibility, easier updates, and deeper system understanding. The guide covers installing Apache, PHP, and MySQL individually, configuring each component, and verifying the setup\u2026","rel":"","context":"In &quot;DevOps&quot;","block_context":{"text":"DevOps","link":"https:\/\/codesamplez.com\/category\/devops"},"img":{"alt_text":"Installing LAMP Stack On Ubuntu","src":"https:\/\/i0.wp.com\/codesamplez.com\/wp-content\/uploads\/2013\/03\/lamp-stack-ubuntu.webp?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/codesamplez.com\/wp-content\/uploads\/2013\/03\/lamp-stack-ubuntu.webp?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/codesamplez.com\/wp-content\/uploads\/2013\/03\/lamp-stack-ubuntu.webp?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/codesamplez.com\/wp-content\/uploads\/2013\/03\/lamp-stack-ubuntu.webp?resize=700%2C400&ssl=1 2x, https:\/\/i0.wp.com\/codesamplez.com\/wp-content\/uploads\/2013\/03\/lamp-stack-ubuntu.webp?resize=1050%2C600&ssl=1 3x, https:\/\/i0.wp.com\/codesamplez.com\/wp-content\/uploads\/2013\/03\/lamp-stack-ubuntu.webp?resize=1400%2C800&ssl=1 4x"},"classes":[]},{"id":57682,"url":"https:\/\/codesamplez.com\/development\/messaging-systems-comparison","url_meta":{"origin":571,"position":2},"title":"Message Queue Comparison &#8211; Kafka vs RabbitMQ vs SQS\/SNS","author":"Rana Ahsan","date":"December 30, 2024","format":false,"excerpt":"Choosing the wrong messaging system can cripple your distributed architecture. This comprehensive guide compares Kafka, RabbitMQ, Amazon SQS, and SNS \u2013 examining their strengths, performance characteristics, and ideal use-cases. Discover which messaging platform perfectly matches your scalability needs and technical requirements. Make the right choice from the start.","rel":"","context":"In &quot;Development&quot;","block_context":{"text":"Development","link":"https:\/\/codesamplez.com\/category\/development"},"img":{"alt_text":"message queue comparison","src":"https:\/\/i0.wp.com\/codesamplez.com\/wp-content\/uploads\/2024\/12\/message-queue-comparison.webp?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/codesamplez.com\/wp-content\/uploads\/2024\/12\/message-queue-comparison.webp?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/codesamplez.com\/wp-content\/uploads\/2024\/12\/message-queue-comparison.webp?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/codesamplez.com\/wp-content\/uploads\/2024\/12\/message-queue-comparison.webp?resize=700%2C400&ssl=1 2x, https:\/\/i0.wp.com\/codesamplez.com\/wp-content\/uploads\/2024\/12\/message-queue-comparison.webp?resize=1050%2C600&ssl=1 3x, https:\/\/i0.wp.com\/codesamplez.com\/wp-content\/uploads\/2024\/12\/message-queue-comparison.webp?resize=1400%2C800&ssl=1 4x"},"classes":[]},{"id":43905,"url":"https:\/\/codesamplez.com\/programming\/resource-pool-java","url_meta":{"origin":571,"position":3},"title":"Java Resource Pool: Efficient Resource Management","author":"Rana Ahsan","date":"July 12, 2024","format":false,"excerpt":"This article explores creating a custom resource pool in Java, a reusable collection of resources like database connections, shared among multiple consumers. It explains the need for resource pools to manage scarce resources efficiently and provides a guide to implementing one using classes like Resource and ResourcePool.","rel":"","context":"In &quot;Programming&quot;","block_context":{"text":"Programming","link":"https:\/\/codesamplez.com\/category\/programming"},"img":{"alt_text":"Java Resource Pool","src":"https:\/\/i0.wp.com\/codesamplez.com\/wp-content\/uploads\/2024\/07\/java-resource-pool.webp?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/codesamplez.com\/wp-content\/uploads\/2024\/07\/java-resource-pool.webp?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/codesamplez.com\/wp-content\/uploads\/2024\/07\/java-resource-pool.webp?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/codesamplez.com\/wp-content\/uploads\/2024\/07\/java-resource-pool.webp?resize=700%2C400&ssl=1 2x, https:\/\/i0.wp.com\/codesamplez.com\/wp-content\/uploads\/2024\/07\/java-resource-pool.webp?resize=1050%2C600&ssl=1 3x, https:\/\/i0.wp.com\/codesamplez.com\/wp-content\/uploads\/2024\/07\/java-resource-pool.webp?resize=1400%2C800&ssl=1 4x"},"classes":[]},{"id":24213,"url":"https:\/\/codesamplez.com\/devops\/self-hosted-git-server","url_meta":{"origin":571,"position":4},"title":"Self-Hosted Git Server: A Complete Guide","author":"Rana Ahsan","date":"August 24, 2014","format":false,"excerpt":"Take control of your code and deployment process with a self-hosted Git server. This guide walks you through setting up your own Git infrastructure with automated deployments using Git hooks, eliminating the need for third-party services while giving you complete flexibility over your development workflow.","rel":"","context":"In &quot;DevOps&quot;","block_context":{"text":"DevOps","link":"https:\/\/codesamplez.com\/category\/devops"},"img":{"alt_text":"Self Hosted Git Server","src":"https:\/\/i0.wp.com\/codesamplez.com\/wp-content\/uploads\/2014\/08\/self-hosted-git-server.webp?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/codesamplez.com\/wp-content\/uploads\/2014\/08\/self-hosted-git-server.webp?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/codesamplez.com\/wp-content\/uploads\/2014\/08\/self-hosted-git-server.webp?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/codesamplez.com\/wp-content\/uploads\/2014\/08\/self-hosted-git-server.webp?resize=700%2C400&ssl=1 2x, https:\/\/i0.wp.com\/codesamplez.com\/wp-content\/uploads\/2014\/08\/self-hosted-git-server.webp?resize=1050%2C600&ssl=1 3x, https:\/\/i0.wp.com\/codesamplez.com\/wp-content\/uploads\/2014\/08\/self-hosted-git-server.webp?resize=1400%2C800&ssl=1 4x"},"classes":[]},{"id":58136,"url":"https:\/\/codesamplez.com\/devops\/deploy-static-website-aws-s3-cloudfront","url_meta":{"origin":571,"position":5},"title":"Host Static Website With AWS S3 And CloudFront &#8211; Step By Step","author":"Rana Ahsan","date":"March 7, 2025","format":false,"excerpt":"Hosting your front-end with AWS S3 and CloudFront changes everything. I\u2019m talking near-zero downtime, unstoppable performance, and total simplicity. Let me share my personal journey\u2014triumphs, embarrassing mistakes, and practical tips\u2014to ensure your website soars at lightning speed, while staying rock-solid, no matter what. Ready? Let\u2019s go get unstoppable right now!","rel":"","context":"In &quot;DevOps&quot;","block_context":{"text":"DevOps","link":"https:\/\/codesamplez.com\/category\/devops"},"img":{"alt_text":"static website deployment s3 cloudfront","src":"https:\/\/i0.wp.com\/codesamplez.com\/wp-content\/uploads\/2025\/03\/static-website-deployment-s3-cloudfront.webp?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/codesamplez.com\/wp-content\/uploads\/2025\/03\/static-website-deployment-s3-cloudfront.webp?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/codesamplez.com\/wp-content\/uploads\/2025\/03\/static-website-deployment-s3-cloudfront.webp?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/codesamplez.com\/wp-content\/uploads\/2025\/03\/static-website-deployment-s3-cloudfront.webp?resize=700%2C400&ssl=1 2x, https:\/\/i0.wp.com\/codesamplez.com\/wp-content\/uploads\/2025\/03\/static-website-deployment-s3-cloudfront.webp?resize=1050%2C600&ssl=1 3x, https:\/\/i0.wp.com\/codesamplez.com\/wp-content\/uploads\/2025\/03\/static-website-deployment-s3-cloudfront.webp?resize=1400%2C800&ssl=1 4x"},"classes":[]}],"_links":{"self":[{"href":"https:\/\/codesamplez.com\/wp-json\/wp\/v2\/posts\/571","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/codesamplez.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/codesamplez.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/codesamplez.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/codesamplez.com\/wp-json\/wp\/v2\/comments?post=571"}],"version-history":[{"count":2,"href":"https:\/\/codesamplez.com\/wp-json\/wp\/v2\/posts\/571\/revisions"}],"predecessor-version":[{"id":58726,"href":"https:\/\/codesamplez.com\/wp-json\/wp\/v2\/posts\/571\/revisions\/58726"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/codesamplez.com\/wp-json\/wp\/v2\/media\/58725"}],"wp:attachment":[{"href":"https:\/\/codesamplez.com\/wp-json\/wp\/v2\/media?parent=571"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/codesamplez.com\/wp-json\/wp\/v2\/categories?post=571"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/codesamplez.com\/wp-json\/wp\/v2\/tags?post=571"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}