Skip to content

Instantly share code, notes, and snippets.

@kolbaba
Last active October 28, 2019 20:32
Show Gist options
  • Save kolbaba/3e402cbc2e379e800a327dd9461ba664 to your computer and use it in GitHub Desktop.
Save kolbaba/3e402cbc2e379e800a327dd9461ba664 to your computer and use it in GitHub Desktop.
PageSpeed Info

PageSpeed

Note: This needs to be updated/merged with whatever other documentation I have regarding PageSpeed stuff. 10-28-2019

.htaccess SPEED UP scripts

<ifModule mod_gzip.c>  
mod_gzip_on Yes  
mod_gzip_dechunk Yes  
mod_gzip_item_include file .(html?|txt|css|js|php|pl)$ mod_gzip_item_include handler ^cgi-script$ mod_gzip_item_include mime ^text/.*  
mod_gzip_item_include mime ^application/x-javascript.* mod_gzip_item_exclude mime ^image/.* mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.* </ifModule>

AddOutputFilterByType DEFLA TE text/plain AddOutputFilterByType DEFLA TE text/html AddOutputFilterByType DEFLA TE text/xml AddOutputFilterByType DEFLA TE text/css AddOutputFilterByType DEFLA TE application/xml AddOutputFilterByType DEFLA TE application/xhtml+xml AddOutputFilterByType DEFLA TE application/rss+xml AddOutputFilterByType DEFLA TE application/javascript AddOutputFilterByType DEFLA TE application/x-javascript

# BEGIN Expire headers <ifModule mod_expires.c>

ExpiresActive On  
ExpiresDefault "access plus 2 days"  
ExpiresByType image/x-icon "access plus 2592000 seconds"  
ExpiresByType image/jpeg "access plus 2592000 seconds"  
ExpiresByType image/png "access plus 2592000 seconds"  
ExpiresByType image/gif "access plus 2592000 seconds"  
ExpiresByType application/x-shockwave-flash "access plus 2592000 seconds" ExpiresByType text/css "access plus 604800 seconds"  
ExpiresByType text/javascript "access plus 216000 seconds"  
ExpiresByType application/javascript "access plus 216000 seconds" ExpiresByType application/x-javascript "access plus 216000 seconds" ExpiresByType text/html "access plus 600 seconds"  
ExpiresByType application/xhtml+xml "access plus 600 seconds"

</ifModule>  
# END Expire headers

# BEGIN Caching <ifModule mod_headers.c>

<filesMatch "\\.(ico|pdf|flv|jpg|jpeg|png|gif|swf|svg)$"> Header set Cache-Control "max-age=2592000, public"

</filesMatch> <filesMatch "\\.(css|js)$">

Header set Cache-Control "max-age=604800, public" </filesMatch>  
<filesMatch "\\.(xml|txt)$">

Header set Cache-Control "max-age=216000, public, must-revalidate" </filesMatch>  
<filesMatch "\\.(html|htm|php)$">

Header set Cache-Control "max-age=3600, public, must-revalidate" </filesMatch>

</ifModule>  
# END Caching

.htaccess to fool Google (experimental)

## WEBP switch
RewriteBase /
# IF request from Page Speed
RewriteCond %{HTTP_USER_AGENT} "Google Page Speed Insights" [OR]
# AND does a webp image exists?
RewriteCond %{DOCUMENT_ROOT}/$1\.webp -f
# THEN send the webp image and set the env var webp
RewriteRule (.+)\.(?:jpe?g|png)$ $1.webp [NC,T=image/webp,E=webp,L]
# If REDIRECT_webp env var exists, append Accept to the Vary header Header append Vary Accept env=REDIRECT_webp
## WEBP switch
Header append Vary Accept env=REQUEST_image AddType image/webp .webp

Links

Webp Example

<picture>
<source srcset="logo.webp" type="image/webp">
<img src="logo.png" alt="Site Logo"> </picture>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment