日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 前端技术 > HTML >内容正文

HTML

前端性能优化:Add Expires headers

發(fā)布時(shí)間:2023/12/2 HTML 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 前端性能优化:Add Expires headers 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

合理設(shè)置 HTTP緩存

緩存的力量是強(qiáng)大的,恰當(dāng)?shù)木彺嬖O(shè)置可以大大的減少 HTTP請(qǐng)求。

  • 很少變化的圖片資源可以直接通過 HTTP Header中的Expires設(shè)置一個(gè)很長的過期頭 ;
  • 變化不頻繁而又可能會(huì)變的資源可以使用 Last-Modifed來做請(qǐng)求驗(yàn)證。
  • (1)Apache 服務(wù)器配置 Expires headers-----.htaccess 文件(根目錄下的隱藏文件)

    <IfModule mod_expires.c> #開啟 Expires headers ExpiresActive On #默認(rèn)的過期時(shí)間 ExpiresDefault "access plus 1 month" Cache-Control max-age=2592000 #針對(duì) ICON 文件的配置 ExpiresByType image/x-icon "access plus 1 year" #針對(duì)圖片的配置 ExpiresByType image/gif "access plus 1 month" ExpiresByType image/png "access plus 1 month" ExpiresByType image/jpg "access plus 1 month" ExpiresByType image/jpeg "access plus 1 month" #針對(duì) CSS 文件的配置 ExpiresByType text/css "access 1 month" #針對(duì) JavaScript 文件的配置 ExpiresByType application/javascript "access plus 1 year" </IfModule>

    (2)Ngnix 服務(wù)器配置 Expires headers-----nginx.conf配置文件

    server {# cache static fileslocation ~* \.(gif|jpe?g|png|ico|swf)$ {# d - 天# h - 小時(shí)# m - 分鐘expires 168h;add_header Pragma public;add_header Cache-Control "public, must-revalidate, proxy-revalidate";}# 由于js和css文件需要改動(dòng),設(shè)置的時(shí)間為5分鐘location ~* \.(css|js)$ {expires 5m;add_header Pragma public;add_header Cache-Control "public, must-revalidate, proxy-revalidate";} }

    總結(jié)

    以上是生活随笔為你收集整理的前端性能优化:Add Expires headers的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。