Skip to content

Instantly share code, notes, and snippets.

@solancer
Last active January 11, 2023 07:25
Show Gist options
  • Star 18 You must be signed in to star a gist
  • Fork 12 You must be signed in to fork a gist
  • Save solancer/1e87950a8fc9c22473287358a5df924b to your computer and use it in GitHub Desktop.
Save solancer/1e87950a8fc9c22473287358a5df924b to your computer and use it in GitHub Desktop.
mod_pagespeed .htaccess configuration
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access 1 year"
ExpiresByType image/jpeg "access 1 year"
ExpiresByType image/gif "access 1 year"
ExpiresByType image/png "access 1 year"
ExpiresByType text/css "access 1 month"
ExpiresByType text/html "access 1 month"
ExpiresByType application/pdf "access 1 month"
ExpiresByType text/x-javascript "access 1 month"
ExpiresByType application/x-shockwave-flash "access 1 month"
ExpiresByType image/x-icon "access 1 year"
ExpiresDefault "access 1 month"
</IfModule>
RewriteEngine On
#Begin gzip and deflate
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/html text/css application/x-javascript text/plain text/xml image/x-icon
</IfModule>
<IfModule pagespeed_module>
ModPagespeed on
ModPagespeedEnableFilters rewrite_css,combine_css
ModPagespeedEnableFilters recompress_images
ModPagespeedEnableFilters convert_png_to_jpeg,convert_jpeg_to_webp
ModPagespeedEnableFilters collapse_whitespace,remove_comments
</IfModule>
@arth2o
Copy link

arth2o commented May 6, 2017

Great config, thanks!

@hafizhff
Copy link

Thank you, this config help me to increase page speed of my website.

@JimmyJamesJameson
Copy link

JimmyJamesJameson commented Jan 23, 2018

Take care with

convert_jpeg_to_webp

It will convert all your images to wepp format that actually isn´t accepted for some browsers such as Firefox. It will be a disaster cause all your images will be broken in firefox users.... And it is really difficult to reverse

Regards

@london-hobo
Copy link

After it some of my pictures became broken (404), any idea why it happens?
After cache flushing everything fine. For a few hours...

@jtibrewala
Copy link

So if I have pagespeed.conf in mods-available in the apache folder, how then should I configure what is given here? Because all the pagespeed related settings are done in that file, right? Want to try to set this up for wordpress, so want to make sure I get it right.

@ofmarconi
Copy link

It would be interesting to update someone, does it really not let the images load in Firefox?

@fmp777
Copy link

fmp777 commented May 4, 2021

(necro)
All major browsers now support webp, so the firefox info is no longer true. Only caveat is macs prior to Big Sur operating system running safari.
(source) https://caniuse.com/?search=webp

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment