本帖最後由 pootor 於 2013-5-26 09:37 編輯 % U, C9 a: ^" O* U1 }1 V3 a
5 | [ @& [3 z+ j+ M S% \& Y, Y
把下面的代碼複製,添加到你網站根目錄的.htaccess裡面去(某些主機可能需要打開隱藏文件顯示)。
- u+ d( ]' n; N5 N' c6 [( a/ g' Z5 B
都有解釋,應該通用,如果你經常改 css 文件,可以把 css哪行的緩存時間設短點。
7 s6 N+ x4 H# z4 b: t# w& _6 i8 B1 D& k
用了這個,速度會有所提升,我只能幫你這些了- # BEGIN Configure entity tags) `. k N9 p# s
- FileETag none
. O9 X, c0 g# Z+ c, s2 h - # END Configure entity tags6 K: g( t2 s( G$ ~; `, I' l
: M# t" s5 o1 k2 J& C( v! d: Z- # BEGIN leverage-browser-caching
2 J+ ?2 O* J" o" D' p5 E6 P+ @ - <IfModule mod_expires.c>
9 a) L' ]; }# q% C- X - ExpiresActive on
, z% f" b- `. P" r# q - # Perhaps better to whitelist expires rules? Perhaps.
`: r& G4 V, p* t - ExpiresDefault "access plus 1 month"
, H, ?+ w- H2 F# e/ ]4 }, K - # cache.appcache needs re-requests8 C% j3 i* p; }7 P6 }5 ^/ ~
- # in FF 3.6 (thx Remy ~Introducing HTML5). p, q& s- j" K; {# G: G* J4 L" a6 |
- ExpiresByType text/cache-manifest "access plus 0 seconds"
+ V, Z$ a7 ]7 N - # Your document html
. p' H* q/ h% X( l: F - ExpiresByType text/html "access plus 0 seconds"
! t c' e; b7 g% `- _ - # Data
+ O) f- J6 O y - ExpiresByType text/xml "access plus 0 seconds"$ J+ f+ i% y! H5 K% P: Z
- ExpiresByType application/xml "access plus 0 seconds"7 P( T/ R5 y' W$ W0 g$ ?$ \
- ExpiresByType application/json "access plus 0 seconds"
( X& @7 M7 |4 ]# D2 ~8 v4 p: J+ }- m - # RSS feed. U B" G) k/ Y; a" s% O6 u
- ExpiresByType application/rss+xml "access plus 1 hour"9 @* P8 y7 Y$ @+ E- {. e& w. P+ q
- # Favicon (cannot be renamed)) U( e4 c, ]( ?. o4 Y
- ExpiresByType image/x-icon "access plus 1 week": P+ q: m: Y* O/ o% b, B0 J
- # Media: images, video, audio
8 s2 z/ e- X3 a8 v- }1 A5 B4 j% [ - ExpiresByType image/gif "access plus 1 month"# Z4 o0 E2 Z( h4 g& T; B6 f
- ExpiresByType image/png "access plus 1 month" S: t0 o. X1 `1 D9 W+ P' m
- ExpiresByType image/jpg "access plus 1 month"2 e: H+ U4 I* e" W6 K" \
- ExpiresByType image/jpeg "access plus 1 month"* p( L/ O8 B$ e6 k
- ExpiresByType video/ogg "access plus 1 month"
) V6 W6 O. Q }9 W' H - ExpiresByType audio/ogg "access plus 1 month"% _7 }, R4 ?9 L, @9 c
- ExpiresByType video/mp4 "access plus 1 month"8 g+ P5 N& c& W# i7 l
- ExpiresByType video/webm "access plus 1 month"* N7 O2 U6 T7 U! N( H' U
- # HTC files (css3pie): x9 _& h) d& W3 s6 M5 _
- ExpiresByType text/x-component "access plus 1 month"
/ d8 f& s, i" k6 T; G' `0 F - # Webfonts. ^9 H6 u# v1 g7 n
- ExpiresByType font/truetype "access plus 1 month"* t J4 }9 Q& m8 u1 N( E
- ExpiresByType font/opentype "access plus 1 month"5 n2 \7 K" K3 U( t6 }/ s6 d' [: c
- ExpiresByType application/x-font-woff "access plus 1 month"# [$ {/ m! t x, w! W- A* {8 H" {
- ExpiresByType image/svg+xml "access plus 1 month"
8 B, G: d% v+ U8 y: ~ - ExpiresByType application/vnd.ms-fontobject "access plus 1 month"+ f, q7 `/ X1 w# u; B1 |# ^' d" x
- # CSS and JavaScript
& ^7 }9 d0 a; H* k% ` - ExpiresByType text/css "access plus 1 year" N2 }# V0 Q7 ?' @4 U
- ExpiresByType application/javascript "access plus 1 year": j5 N3 D6 O( X5 Q+ t, ~5 V+ h
- ExpiresByType text/javascript "access plus 1 year"
/ \& L, l% ^/ Q# q" [3 d - <IfModule mod_headers.c>5 X9 |; n/ N/ U2 _ z
- Header append Cache-Control "public"9 a+ D- X* J' {" R$ }' [
- </IfModule>+ D8 W9 z- o7 J
- </IfModule>5 X1 n# A P/ g1 D
- # END leverage-browser-caching
複製代碼 |