code-8
code-8

Reputation: 58810

Serve static assets with an efficient cache policy via nginx

I'm trying to increase the performance of my site. I got about ~83 right now accordingly Google Page Speed Insight. While it's not the worst, it's not great either. One of the issues is caching, I need to leverage caching and increase the long life of my static assets.

enter image description here

My site is behind Cloudflare. Do I need to apply any settings there?

Upvotes: 1

Views: 1648

Answers (1)

code-8
code-8

Reputation: 58810

add these lines to : /etc/nginx/sites-available/default

# Media: images, icons, video, audio, HTC
location ~* \.(?:jpg|jpeg|gif|png|ico|cur|gz|svg|svgz|mp4|mp3|wav|ogg|ogv|webm|htc|woff2|woff)$ {
    expires 1M;
    access_log off;
    add_header Cache-Control "public";
}

and service nginx reload

Result

enter image description here

Upvotes: 2

Related Questions