diklein
February 16, 2017, 12:54am
1
Google PageSpeed recommends that I “leverage browser caching” for my CSS by “setting a maximum age in the HTTP headers.” How does one do this with Jekyll?
The good news is there are a bunch of options and resources available to you since what you want to do isn’t specific to Jekyll.
Depending on the server type you’re using to host your site this will vary, but if you’re using Apache you can set caching headers via a .htaccess
file.
HTML5 Boilerplate has a really good one that is heavily commented that walks through all kinds of good things you’ll want to enable for improved performance (gzip compression, etc.) and security.
1 Like
diklein
February 16, 2017, 1:49am
3
Thanks! Now I’m trying to figure out how to do this without .htaccess since I’m using nginx.
They also have server configs for nginx
# Expire rules for static content
# No default expire rule. This config mirrors that of apache as outlined in the
# html5-boilerplate .htaccess file. However, nginx applies rules by location,
# the apache rules are defined by type. A consequence of this difference is that
# if you use no file extension in the url and serve html, with apache you get an
# expire time of 0s, with nginx you'd get an expire header of one month in the
# future (if the default expire rule is 1 month). Therefore, do not use a
# default expire rule with nginx unless your site is completely static
# cache.appcache, your document html and data
location ~* \.(?:manifest|appcache|html?|xml|json)$ {
add_header Cache-Control "max-age=0";
}
# Feed
location ~* \.(?:rss|atom)$ {
add_header Cache-Control "max-age=3600";
}
This file has been truncated. show original
# Configuration File - Nginx Server Configs
# http://nginx.org/en/docs/dirindex.html
# Run as a unique, less privileged user for security reasons.
# Default: nobody nobody
user www www;
# Sets the worker threads to the number of CPU cores available in the system for best performance.
# Should be > the number of CPU cores.
# Maximum number of connections = worker_processes * worker_connections
# Default: 1
worker_processes auto;
# Maximum number of open files per worker process.
# Should be > worker_connections.
# Default: no limit
worker_rlimit_nofile 8192;
events {
# If you need more connections than this, you start optimizing your OS.
This file has been truncated. show original
diklein
February 16, 2017, 6:20pm
5
@mmistakes Thanks! I also found this:
adamwalz.net.nginxconf
server {
server_name www.adamwalz.net;
return 301 $scheme://adamwalz.net$request_uri;
}
server {
server_name adamwalz.net *.adamwalz.net;
root /home/adamwalz/Sites/adamwalz.net;
access_log /var/log/nginx/adamwalz.net/access.log;
This file has been truncated. show original
jekyll_server.nginxconf
location / {
index index.html index.htm;
if (-f $document_root/maintenance.html) {
return 503;
}
location ~* \.(css|js|html)$ {
expires max;
}
This file has been truncated. show original
nginx.conf
user www-data;
worker_processes 4;
pid /var/run/nginx.pid;
events {
worker_connections 768;
# multi_accept on;
}
http {
This file has been truncated. show original
There are more than three files. show original
Hi - I’m trying to resolve the same issue you were working on - did you ever figure it out? I see this github that you posted - is it just a matter of copying these files over to the root directory of my jekyll blog? Thank you in advance!
Do I just paste these files in the root of my jekyll blog?