通过 nginx 使用高效的缓存策略提供静态资源

发布于 2025-01-16 20:12:41 字数 307 浏览 5 评论 0原文

我正在努力提高网站的性能。根据 Google Page Speed Insight,我现在得到了大约 83 分。虽然这不是最糟糕的,但也不是很好。问题之一是缓存,我需要利用缓存并延长静态资产的使用寿命。

输入图片此处描述

我的网站位于 Cloudflare 后面。我需要在那里应用任何设置吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夏末的微笑 2025-01-23 20:12:41

将这些行添加到: /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";
}

service nginx reload

结果

在此处输入图像描述

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文