Skip to content

Commit

Permalink
perf: improved browser caching, closes #3025
Browse files Browse the repository at this point in the history
  • Loading branch information
thorsten committed Jun 26, 2024
1 parent 6c626fb commit c91a216
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
22 changes: 22 additions & 0 deletions nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,28 @@ server {
gzip_buffers 16 8k;
gzip_disable "MSIE [1-6]\.(?!.*SV1)";

location ~* \.(jpg|jpeg|gif|png|webp|svg|ico|mp4|webm|mpeg|ttf|otf|woff|woff2|css|js|pdf)$ {
expires 1y;
add_header Cache-Control "public";
}

# Additional configurations for specific file types
location ~* \.(svg|eot|ttf|woff|woff2)$ {
add_header Access-Control-Allow-Origin "*";
}

# Specific cache-control for javascript files
location ~* \.(js)$ {
expires 1y;
add_header Cache-Control "public, max-age=31536000, immutable";
}

# Specific cache-control for CSS files
location ~* \.(css)$ {
expires 1y;
add_header Cache-Control "public, max-age=31536000, immutable";
}

# Rewrite logging, should be turned off on production
rewrite_log on

Expand Down
43 changes: 43 additions & 0 deletions phpmyfaq/.htaccess
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,49 @@ Header always append X-Frame-Options SAMEORIGIN
AddOutputFilterByType DEFLATE text/xml
</IfModule>

# Enable Expires headers to set expiration dates for various file types
<IfModule mod_expires.c>
ExpiresActive On

# Set expiration for image files to 1 year
ExpiresByType image/jpeg "access plus 1 year"
ExpiresByType image/gif "access plus 1 year"
ExpiresByType image/png "access plus 1 year"
ExpiresByType image/webp "access plus 1 year"
ExpiresByType image/svg+xml "access plus 1 year"
ExpiresByType image/x-icon "access plus 1 year"

# Set expiration for video files to 1 year
ExpiresByType video/webm "access plus 1 year"
ExpiresByType video/mp4 "access plus 1 year"
ExpiresByType video/mpeg "access plus 1 year"

# Set expiration for font files to 1 year
ExpiresByType font/ttf "access plus 1 year"
ExpiresByType font/otf "access plus 1 year"
ExpiresByType font/woff "access plus 1 year"
ExpiresByType font/woff2 "access plus 1 year"
ExpiresByType application/font-woff "access plus 1 year"
ExpiresByType application/font-woff2 "access plus 1 year"

# Set expiration for CSS and JavaScript files to 1 year
ExpiresByType text/css "access plus 1 year"
ExpiresByType text/javascript "access plus 1 year"
ExpiresByType application/javascript "access plus 1 year"

# Set expiration for other file types to 1 year
ExpiresByType application/pdf "access plus 1 year"
ExpiresByType image/vnd.microsoft.icon "access plus 1 year"
</IfModule>

# Enable Cache-Control headers to set caching policies for various file types
<IfModule mod_headers.c>
<FilesMatch "\.(flv|gif|ico|jpg|jpeg|mp4|mpeg|png|svg|swf|webp|webm|js|pdf|css|woff|woff2)$">
Header set Cache-Control "max-age=31536000, public"
</FilesMatch>
</IfModule>


# if you want to use mod_rewrite, set this 'On'
RewriteEngine On

Expand Down

0 comments on commit c91a216

Please sign in to comment.