Skip to content

Instantly share code, notes, and snippets.

@shankar-bavan
Created December 25, 2022 14:17
Show Gist options
  • Save shankar-bavan/90788d4e4ffae91fc712c60dcdbb9c29 to your computer and use it in GitHub Desktop.
Save shankar-bavan/90788d4e4ffae91fc712c60dcdbb9c29 to your computer and use it in GitHub Desktop.
Laravel htaccess optimization

Laravel htaccess optimization can be helped for increasing your website page speed by image caching, HTML compression, Gzip Compression, Enable Browser Caching, Expires headers to leverage browser caching. Open your htaccess file and add the code snippet given below at the end of your site.

## EXPIRES CACHING ##
<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 application/pdf "access 1 month"
ExpiresByType application/javascript "access 1 month"
ExpiresByType application/x-javascript "access 1 month"
ExpiresByType application/x-shockwave-flash "access 1 month"
ExpiresByType image/x-icon "access 1 year"
ExpiresDefault "access 2 days"
</IfModule>

# GZIP COMPRESSION
# compress text, html, javascript, css, xml:
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript

# compress HTML
<files *.html>
SetOutputFilter DEFLATE
</files>
# GZIP COMPRESSION
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment