Skip to content

Instantly share code, notes, and snippets.

@harishkotra
Created October 9, 2017 10:47
Show Gist options
  • Save harishkotra/617d710604a40f1417f700eb0352bf3d to your computer and use it in GitHub Desktop.
Save harishkotra/617d710604a40f1417f700eb0352bf3d to your computer and use it in GitHub Desktop.
.htaccess hacks for speeding up WordPress
#Enable Keep-Alive
#Keep alive is a method to allow the same tcp connection for HTTP conversation instead of opening a new one with each new request.
#More simply put, it is a communication between the web server and the web browser that says "you can grab more than just one file at a time".
#Keep alive is also known as a persistant connection
<IfModule mod_headers.c>
Header set Connection keep-alive
</IfModule>
#Enable gzip
#Gzip is a method of compressing files (making them smaller) for faster network transfers.
#It is also a file format.
<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>
#Add Expires Headers
#Expire Headers is letting your browser to cache your website content and request them only after the time specified in that rule expires.
<FilesMatch "(?i)^.*\.(ico|flv|jpg|jpeg|png|gif|js|css|woff)$">
ExpiresActive On
ExpiresDefault A2592000
</FilesMatch>
#Compress components with gzip
<IfModule mod_deflate.c>
# Compress HTML, CSS, JavaScript, Text, XML and fonts
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/vnd.ms-fontobject
AddOutputFilterByType DEFLATE application/x-font
AddOutputFilterByType DEFLATE application/x-font-opentype
AddOutputFilterByType DEFLATE application/x-font-otf
AddOutputFilterByType DEFLATE application/x-font-truetype
AddOutputFilterByType DEFLATE application/x-font-ttf
AddOutputFilterByType DEFLATE application/x-javascript
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE font/opentype
AddOutputFilterByType DEFLATE font/otf
AddOutputFilterByType DEFLATE font/ttf
AddOutputFilterByType DEFLATE image/svg+xml
AddOutputFilterByType DEFLATE image/x-icon
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/javascript
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/xml
# Remove browser bugs (only needed for really old browsers)
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
Header append Vary User-Agent
</IfModule>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment