Speed Up Sites with htaccess Caching

Thảo luận trong 'SEO for XenForo' bắt đầu bởi dang khoa, 5/12/13.

1votes
5/5, 1 vote

  1. dang khoa

    dang khoa New Member

    Bài viết:
    20
    Likes :
    3
    Rất hữu ích cho SEO

    iFModule for fail-safe .htaccess ^
    At least one of the 2 modules needs to be built into Apache; although they are included in the distribution, they are not turned on by default. To find out if the modules are enabled in your server, find the httpd binary and run httpd -l; this should print a list of the available modules. The modules we're looking for are mod_expires and mod_headers.

    If they aren't available, and you have administrative access, you can recompile Apache to include them. This can be done either by uncommenting the appropriate lines in the Configuration file, or using the -enable-module=expires and -enable-module=headers arguments to configure (1.3 or greater).

    Mã:
    <ifModule mod_expires.c>
    # any Expires Directives go here
    </ifModule>
    <ifModule mod_headers.c>
    # any Header directives go here
    </ifModule>
    Apache .htaccess caching code ^

    Mã:
    # 1 YEAR
    <FilesMatch "\.(ico|pdf|flv)$">
    Header set Cache-Control "max-age=29030400, public"
    </FilesMatch>
    # 1 WEEK
    <FilesMatch "\.(jpg|jpeg|png|gif|swf)$">
    Header set Cache-Control "max-age=604800, public"
    </FilesMatch>
    # 2 DAYS
    <FilesMatch "\.(xml|txt|css|js)$">
    Header set Cache-Control "max-age=172800, proxy-revalidate"
    </FilesMatch>
    # 1 MIN
    <FilesMatch "\.(html|htm|php)$">
    Header set Cache-Control "max-age=60, private, proxy-revalidate"
    </FilesMatch>
    Caching with mod_expires ^
    This module controls the setting of the Expires HTTP header and the max-age directive of the Cache-Control HTTP header in server responses. The expiration date can set to be relative to either the time the source file was last modified, or to the time of the client access.

    These HTTP headers are an instruction to the client about the document's validity and persistence. If cached, the document may be fetched from the cache rather than from the source until this time has passed. After that, the cache copy is considered "expired" and invalid, and a new copy must be obtained from the source.

    mod_expires Caching ex. 1 ^
    Mã:
    <ifModule mod_expires.c>
    ExpiresActive On
    ExpiresDefault A300
    ExpiresByType image/x-icon A2592000
    ExpiresByType application/x-javascript A3600
    ExpiresByType text/css A3600
    ExpiresByType image/gif A604800
    ExpiresByType image/png A604800
    ExpiresByType image/jpeg A604800
    ExpiresByType text/plain A300
    ExpiresByType application/x-shockwave-flash A604800
    ExpiresByType video/x-flv A604800
    ExpiresByType application/pdf A604800
    ExpiresByType text/html A300
    </ifModule>
    mod_expires Caching ex. 2 ^

    Mã:
    <ifModule mod_expires.c>
    ExpiresActive On
    ExpiresByType image/gif A2592000
    ExpiresByType image/png A2592000
    ExpiresByType image/jpg A2592000
    ExpiresByType image/x-icon A2592000
    ExpiresByType application/pdf A2592000
    ExpiresByType application/x-javascript A2592000
    ExpiresByType text/plain A2592000
    # Expires after 4.8 hours
    ExpiresByType text/css A17200
    </ifModule>
    mod_expires Caching ex. 3 ^

    Mã:
    <ifModule mod_expires.c>
    ExpiresActive On
    ExpiresDefault A86400
    ExpiresByType image/x-icon A2592000
    ExpiresByType application/x-javascript A2592000
    ExpiresByType text/css A2592000
    ExpiresByType image/gif A604800
    ExpiresByType image/png A604800
    ExpiresByType image/jpeg A604800
    ExpiresByType text/plain A604800
    ExpiresByType application/x-shockwave-flash A604800
    ExpiresByType video/x-flv A604800
    ExpiresByType application/pdf A604800
    ExpiresByType text/html A900
    </ifModule>
    Tham khảo thêm ở đây http://www.askapache.com/htaccess/s...ess-caching.html#Apache_htaccess_caching_code
     
    Đang tải...
  2. nguyendungbkc

    nguyendungbkc Verified User

    Bài viết:
    180
    Likes :
    91
    hướng dẫn tiếng việt dc ko bạn ơi, tiếng anh ko hiểu chi tiết
     
  3. vlook24net

    vlook24net New Member

    Bài viết:
    62
    Likes :
    11
    chỉ là leech về thôi ,biết j mà hướng dẫn
     
  4. AC_Khanh01

    AC_Khanh01 Member

    Bài viết:
    221
    Likes :
    61
    Cái này hay nè :D giảm tải cho server :D
     
  5. vbt.dongnguyen

    vbt.dongnguyen Member

    Bài viết:
    180
    Likes :
    102
    Có ai giải thích hộ mấy câu lệnh trong đó ko??
     
  6. AC_Khanh01

    AC_Khanh01 Member

    Bài viết:
    221
    Likes :
    61
    Đại khái là nó sẽ không load những thành phần đã load, mà là dùng cái đã có sẵn trong cache của trình duyệt, và ta có thể chỉ định thời gian để nó refresh lại dữ liệu :D

    Cũng đang tìm hiểu thôi, làm đại thấy Google báo là có nhanh hơn và có giảm tải việc load :D

    Thêm vào .htaccess:

    <ifModule mod_headers.c>
    <filesMatch "\.(jpe?g|png|gif)$">
    Header set Cache-Control "public"
    </filesMatch>
    <filesMatch "\.(css)$">
    Header set Cache-Control "public"
    </filesMatch>
    </ifModule>

    <IfModule mod_expires.c>
    ExpiresActive on
    ExpiresByType text/css "access plus 1 day"
    ExpiresByType text/javascript "access plus 1 month"
    ExpiresByType application/javascript "access plus 1 month"
    ExpiresByType application/x-javascript "access plus 1 month"
    ExpiresByType application/x-shockwave-flash "access plus 1 month"
    ExpiresByType image/gif "access plus 1 month"
    ExpiresByType image/jpg "access plus 1 month"
    ExpiresByType image/jpeg "access plus 1 month"
    ExpiresByType image/png "access plus 1 month"
    ExpiresByType image/ico "access plus 1 month"
    ExpiresByType image/icon "access plus 1 month"
    </IfModule>
     
  7. AC_Khanh01

    AC_Khanh01 Member

    Bài viết:
    221
    Likes :
    61
  8. lh1987

    lh1987 Member

    Bài viết:
    342
    Likes :
    118
    root directory of the cdn domain, and added the below to config.php
    PHP:
    #JS on CDN
    $config['javaScriptUrl'] = 'http://cdn.z22se.com/js';
    and then added the below .htaccess file into the root folder of the cdn domain
    PHP:
    # Turn on Expires and set default to 0
    ExpiresActive On
    ExpiresDefault A0
    # Set up caching on media files for 5 weeks
    <FilesMatch "\.(flv|ico|pdf|avi|mov|ppt|doc|mp3|wmv|wav)$">
    ExpiresDefault A3024000
    Header append Cache
    -Control "public"
    </FilesMatch>
    # Set up caching on media files for 5 weeks
    <FilesMatch "\.(gif|jpg|jpeg|png|swf)$">
    ExpiresDefault A3024000
    Header append Cache
    -Control "public"
    </FilesMatch>
    # Set up 1 day caching on commonly updated files
    <FilesMatch "\.(xml|txt|html|js|css)$">
    ExpiresDefault A604800
    Header append Cache
    -Control "proxy-revalidate"
    </FilesMatch>
    # Force no caching for dynamic files
    <FilesMatch "\.(php|cgi|pl|htm)$">
    ExpiresActive Off
    Header set Cache
    -Control "private, no-cache, no-store, proxy-revalidate, no-transform"
    Header set Pragma "no-cache"
    </FilesMatch>
    Thử xem tốc độ load forum nhanh gấp mấy lần.:))
     
  9. singh

    singh Member

    Bài viết:
    384
    Likes :
    79
    Viết tiếng viết đi mấy chú. Chẳng hỉu làm gì với mấy code này..haizz
     
comments powered by Disqus

Chia sẻ trang này

Đang tải...