Mã nén giúp tăng tốc website và tăng điểm PageSpeed Insights

Thảo luận trong 'Tối ưu Website' bắt đầu bởi jiangdung, 6/12/16.

Đã xem: 2,166

  1. jiangdung Thành Viên

    Bí kíp tăng tốc load website lên 75-90 điểm, tốc độ load web 0.5s :

    + Nén dung lượng ảnh tuyệt đối
    + Tắt hiệu ứng thừa, thay thế slide ảnh nhẹ
    + Nén css, chặn java hệ thống làm nặng web
    + Tăng siêu cache cho web, nén Gzip
    + Giảm tải link out ngoài hệ thống
    + Chèn thêm mã nén cache giảm tải java vào .htacess
    + Mã nén mình gửi ở dưới nhé
    Test tốc độ : http://vincity.thaibinhweb.net/
    PHP:
    Mã nén chèn vào .htacess


    # BEGIN Expire headers
    # END Expire headers
    <ifModule mod_gzip.c>
    mod_gzip_on Yes
    mod_gzip_dechunk Yes
    mod_gzip_item_include file 
    .(html?|txt|css|js|php|pl)$
    mod_gzip_item_include handler ^cgi-script$
    mod_gzip_item_include mime ^text/.*
    mod_gzip_item_include mime ^application/x-javascript.*
    mod_gzip_item_exclude mime ^image/.*
    mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
    </
    ifModule>
    # BEGIN Expire headers
    <ifModule mod_expires.c>
    ExpiresActive On
    ExpiresDefault 
    "access plus 5 seconds"
    ExpiresByType image/x-icon "access plus 12592000 seconds"
    ExpiresByType image/jpeg "access plus 12592000 seconds"
    ExpiresByType image/png "access plus 12592000 seconds"
    ExpiresByType image/gif "access plus 12592000 seconds"
    ExpiresByType application/x-shockwave-flash "access plus 12592000 seconds"
    ExpiresByType text/css "access plus 1604800 seconds"
    ExpiresByType text/javascript "access plus 1216000 seconds"
    ExpiresByType application/javascript "access plus 1216000 seconds"
    ExpiresByType application/x-javascript "access plus 1216000 seconds"
    ExpiresByType text/html "access plus 111600 seconds"
    ExpiresByType application/xhtml+xml "access plus 111600 seconds"
    </ifModule>
    # END Expire headers
    # BEGIN Cache-Control Headers
    <ifModule mod_headers.c>
    <
    filesMatch "\.(ico|jpe?g|png|gif|swf)$">
    Header set Cache-Control "public"
    </filesMatch>
    <
    filesMatch "\.(css)$">
    Header set Cache-Control "public"
    </filesMatch>
    <
    filesMatch "\.(js)$">
    Header set Cache-Control "private"
    </filesMatch>
    <
    filesMatch "\.(x?html?|php)$">
    Header set Cache-Control "private, must-revalidate"
    </filesMatch>
    </
    ifModule>
    # END Cache-Control Headers

    ########## Begin - ETag Optimization
    ## This rule will create an ETag for files based only on the modification
    ## timestamp and their size.
    ## Note: It may cause problems on your server and you may need to remove it
    FileETag MTime Size
    # AddOutputFilterByType is now deprecated by Apache. Use mod_filter in the future.
    AddOutputFilterByType DEFLATE text/plain text/html text/xml text/css application/xml application/xhtml+xml application/rss+xml application/javascript application/x-javascript
    # Enable expiration control
    ExpiresActive On
    # Default expiration: 1 hour after request
    ExpiresDefault "now plus 1 hour"
    # CSS and JS expiration: 1 week after request
    ExpiresByType text/css "now plus 1 week"
    ExpiresByType application/javascript "now plus 1 week"
    ExpiresByType application/x-javascript "now plus 1 week"

    # Image files expiration: 1 month after request
    ExpiresByType image/bmp "now plus 1 month"
    ExpiresByType image/gif "now plus 1 month"
    ExpiresByType image/jpeg "now plus 1 month"
    ExpiresByType image/jp2 "now plus 1 month"
    ExpiresByType image/pipeg "now plus 1 month"
    ExpiresByType image/png "now plus 1 month"
    ExpiresByType image/svg+xml "now plus 1 month"
    ExpiresByType image/tiff "now plus 1 month"
    ExpiresByType image/vnd.microsoft.icon "now plus 1 month"
    ExpiresByType image/x-icon "now plus 1 month"
    ExpiresByType image/ico "now plus 1 month"
    ExpiresByType image/icon "now plus 1 month"
    ExpiresByType text/ico "now plus 1 month"
    ExpiresByType application/ico "now plus 1 month"
    ExpiresByType image/vnd.wap.wbmp "now plus 1 month"
    ExpiresByType application/vnd.wap.wbxml "now plus 1 month"

    ExpiresByType application/smil "now plus 1 month"
    # Audio files expiration: 1 month after request
    ExpiresByType audio/basic "now plus 1 month"
    ExpiresByType audio/mid "now plus 1 month"
    ExpiresByType audio/midi "now plus 1 month"
    ExpiresByType audio/mpeg "now plus 1 month"
    ExpiresByType audio/x-aiff "now plus 1 month"
    ExpiresByType audio/x-mpegurl "now plus 1 month"
    ExpiresByType audio/x-pn-realaudio "now plus 1 month"
    ExpiresByType audio/x-wav "now plus 1 month"

    # Movie files expiration: 1 month after request
    ExpiresByType application/x-shockwave-flash "now plus 1 month"
    ExpiresByType x-world/x-vrml "now plus 1 month"
    ExpiresByType video/x-msvideo "now plus 1 month"
    ExpiresByType video/mpeg "now plus 1 month"
    ExpiresByType video/mp4 "now plus 1 month"
    ExpiresByType video/quicktime "now plus 1 month"
    ExpiresByType video/x-la-asf "now plus 1 month"
    ExpiresByType video/x-ms-asf "now plus 1 month"


    1480997086123screensave.png
     
    Chỉnh sửa cuối: 7/12/16
    Đang tải...
    nam lim xanh

    Bình Luận Bằng Facebook

  2. hellomedia Thành Viên Tiêu Biểu

    Số bài viết: 192
    Đã được thích: 2
    Điểm thành tích: 18
    Web:
    Thấy cái này ảo thế bác, ko phải cài gì vào bộ code à? cứ thế để chạy thôi thì có duy trì đc ko?
    sao bác ko cho ít rì view cụ thể luôn với hướng dẫn nhỉ
     
  3. jiangdung Thành Viên

    Số bài viết: 16
    Đã được thích: 1
    Điểm thành tích: 3
  4. thuygia Thành Viên

    Số bài viết: 29
    Đã được thích: 4
    Điểm thành tích: 8
    Web:
    Bác cho cái link mà sao lại phải để link rút gon thế kia? Mất công chia sẻ thì để công khai full url đi bạn, những cái bác chia sẻ google speed cũng bảo em nhu thế, hài
     
  5. jiangdung Thành Viên

    Số bài viết: 16
    Đã được thích: 1
    Điểm thành tích: 3
  6. KrystalLe Thành Viên

    Số bài viết: 23
    Đã được thích: 3
    Điểm thành tích: 3
    Web:
    bác đang chỉ cách tối ưu cho wordpress hả.
    hiện tại trang test page speed của google nó có chỉ ra các lỗi cần sửa cho mình mà, chịu khó translate rồi nhờ bên code chỉnh lại theo đó là được
     
  7. jiangdung Thành Viên

    Số bài viết: 16
    Đã được thích: 1
    Điểm thành tích: 3
    à mã này dùng cho nhiều loại ....bạn dùng thử xem sao........ bắt viết 150 ký tự cơ à......hic hic load cực nhanh nè http://camerahungha.com/......................
     
  8. bigbangvn Thành Viên

    Số bài viết: 41
    Đã được thích: 2
    Điểm thành tích: 8
    Web:
    Bác có phần mềm nào nén ảnh tốt không vậy? site mình nhiều ảnh dung lượng cao quá nên tốc độ load chậm, đang tìm cách giảm xuống mà chưa tìm được phần mềm nào cả.
     
  9. jiangdung Thành Viên

    Số bài viết: 16
    Đã được thích: 1
    Điểm thành tích: 3
    Mình hay dùng cái này.................khá ổn bạn nhé....FILEminimizer Pictures
    Bạn down về nén thử xem nhé.................. phải viết đủ 150 ký tự à ..............................
     
    bigbangvn thích bài này.
  10. WEB-SEO Thành Viên

    Số bài viết: 11
    Đã được thích: 1
    Điểm thành tích: 1
    Web:
    Cái này chủ thớt đưa ra là đúng nhưng nó cũng có 2 mặt của nó, mình xin chia sẻ để mọi người rút kinh nghiệm hơn nữa nhé.
    Những câu lệnh trên để chỉ định rằng nén và lưu vào bộ nhớ cache của trình duyệt những file mà nó quy định, thời gian giản phóng bộ nhớ cache để load lại các file đó .v.v. để nếu ai đó đã vào trang đó 1 lần rồi thì từ lần thứ 2 trong khoảng thời gian mà chưa giải phóng bộ nhớ cache nó sẽ không phải load lại trực tiếp từ server về nữa mà lấy thông tin từ trình duyệt.
    Như vậy với những người quản trị phải thận trọng, nội dung bài OK rồi và hãy kiểm tra kỹ lại hãy post lên vì post lên rồi và có khách vào rồi thì nó đã lưu thông tin trên máy của khách, admin có sửa lại thì trên máy khách nó cũng không thay đổi, nếu muốn thay đổi thì khách phải xóa bộ nhớ cache trên trình duyệt đi mới thấy hoặc chờ đến hết thời gian lưu bộ nhớ cache. hi hi hi
    trang http://hatchongam.com của mình còn đặt tới 94/100 cho bản di động và 95/100 cho bản desktop cơ chứ không chỉ có 70-90 như thớt đâu thớt à!