Two key configurations for Web performance optimization (WPO). In the future, we will look at how to tune TCP stack on nginx for better performance.
Turn on Gzip for text files
gzip on;
gzip_comp_level 5;
gzip_min_length 1000;
gzip_types application/json text/css application/x-javascript text/javascript;
text/html is always compressed.
Add Expires header to static files
location / {
if ($request_uri ~* \.(ico|css|js|gif|jpe?g|png)$) {
expires 72h;
break;
}
}
# This block will catch static file requests, such as images, css, js
# The ?: prefix is a 'non-capturing' mark, meaning we do not require
# the pattern to be captured into $1 which should help improve performance
location ~* \.(?:ico|css|js|gif|jpe?g|png)$ {
# Some basic cache-control for static files to be sent to the browser
expires max;
add_header Pragma public;
add_header Cache-Control "public, must-revalidate, proxy-revalidate";
}
location ~* \.(ico|css|js|gif|jpe?g|png)(\?[0-9]+)?$ {
expires max;
break;
}
No comments:
Post a Comment