本帖最後由 pootor 於 2013-5-26 09:37 編輯
. E- J# F9 [* R0 x, j! H6 y: |: d9 E1 A& u5 ]* _
把下面的代碼複製,添加到你網站根目錄的.htaccess裡面去(某些主機可能需要打開隱藏文件顯示)。
8 s' i% Y" C" P* e% P& |4 @# n+ j! A% \) o4 F
都有解釋,應該通用,如果你經常改 css 文件,可以把 css哪行的緩存時間設短點。
# W& v+ X8 I6 J6 R; g: l/ o1 c, o
用了這個,速度會有所提升,我只能幫你這些了- # BEGIN Configure entity tags) B N _7 d9 C3 \2 f5 G' G
- FileETag none
1 W* y$ J# t0 P - # END Configure entity tags# W2 w6 ^3 ^. R* ~6 B' Y! d
- 0 g! n) W- p5 P
- # BEGIN leverage-browser-caching/ u0 x8 Q- b2 C' k& q! Q+ k6 x
- <IfModule mod_expires.c>/ q1 k" I3 w& W1 p3 F& W
- ExpiresActive on
/ G5 @+ g* [, Y - # Perhaps better to whitelist expires rules? Perhaps.# O' Z- ?+ M0 l' ?* t
- ExpiresDefault "access plus 1 month"% S0 d) i2 n# r. j/ X
- # cache.appcache needs re-requests+ U8 O2 y' o0 d) C6 B1 ]' y3 b! I
- # in FF 3.6 (thx Remy ~Introducing HTML5)2 ~- G+ B$ j+ ?0 @
- ExpiresByType text/cache-manifest "access plus 0 seconds"
+ n' B1 a3 D, h- ?; ]: N0 | - # Your document html
9 H6 @$ j2 O) W" d - ExpiresByType text/html "access plus 0 seconds"
4 f) |3 \ S4 G+ V3 S0 m" j - # Data
! e8 ]6 N% Q4 i) R7 H, C% r! s - ExpiresByType text/xml "access plus 0 seconds"
: ? ~% U6 s8 L* m1 A9 \ - ExpiresByType application/xml "access plus 0 seconds"
, H: y! U# p1 d* d - ExpiresByType application/json "access plus 0 seconds"
4 g- x# k* u$ ]: w: Y - # RSS feed
$ T1 |( W. p" N) X - ExpiresByType application/rss+xml "access plus 1 hour"
* A: f; F0 w7 k" e8 ^ - # Favicon (cannot be renamed)
4 i) i: \% Q) i: q0 { - ExpiresByType image/x-icon "access plus 1 week"( W' }8 P, I7 v; r1 q* z2 h
- # Media: images, video, audio
" W- A1 ~+ V0 ^7 K) k4 b" D - ExpiresByType image/gif "access plus 1 month"
: \' K: |( g* v7 l8 A* t - ExpiresByType image/png "access plus 1 month"
, z, n3 t- s2 A/ {. C2 m - ExpiresByType image/jpg "access plus 1 month"* z0 j! D8 E: @: v* S
- ExpiresByType image/jpeg "access plus 1 month"
# b$ G5 z. [3 M: B - ExpiresByType video/ogg "access plus 1 month"
( ` x4 U& g7 E3 E - ExpiresByType audio/ogg "access plus 1 month"# O2 C" t6 a: u' X; J6 x1 }
- ExpiresByType video/mp4 "access plus 1 month"$ i$ Q, P+ c7 e) z2 J
- ExpiresByType video/webm "access plus 1 month"
" E1 x. W- k$ B% D: _# G - # HTC files (css3pie)
/ A+ Q. T4 p1 o, f( w7 y9 I) A - ExpiresByType text/x-component "access plus 1 month"3 E5 V/ `/ K- |
- # Webfonts$ a4 \' H# y8 W. n( W7 V
- ExpiresByType font/truetype "access plus 1 month"
, h2 O/ X% W1 S% U - ExpiresByType font/opentype "access plus 1 month"
9 m7 K b1 @5 V% L B) k* j6 O/ b - ExpiresByType application/x-font-woff "access plus 1 month"* W% s" I0 ?. r2 s' M' l: ?
- ExpiresByType image/svg+xml "access plus 1 month"
5 u/ k0 G3 n* q - ExpiresByType application/vnd.ms-fontobject "access plus 1 month"8 b4 v# t+ |, N) A6 i* h3 ]
- # CSS and JavaScript( Y( ?' `! z1 e+ o. R8 }" x! x+ I4 g
- ExpiresByType text/css "access plus 1 year": ?6 N& q |) n
- ExpiresByType application/javascript "access plus 1 year"
! f3 T* X6 d4 \2 V8 _ - ExpiresByType text/javascript "access plus 1 year": k+ S8 C! X+ p
- <IfModule mod_headers.c> S6 U8 w. y' d* l
- Header append Cache-Control "public"
4 b$ |) {) ~! s" T - </IfModule>$ ?% i! E& v; \/ {3 ?
- </IfModule>
; K" T; X, ]8 @. B - # END leverage-browser-caching
複製代碼 |