2013-05-20 31 views

Trả lời

14

Tôi nghĩ bạn phải bật tính năng nén cho các tệp cụ thể như css, jsxml. Các mã sau thêm vào tập tin .htaccess gốc của tên miền của bạn sẽ cho phép loại tính năng trên bạn server:

<IfModule mod_headers.c> 
    <FilesMatch "\.(js|css|xml|gz)$"> 
    Header append Vary: Accept-Encoding 
    </FilesMatch> 
</IfModule> 

Nếu bạn muốn thêm loại tập tin nhiều hơn cho quy tắc này, chỉ đơn giản thêm phần mở rộng của nó đến tuyên bố! <FilesMatch "\.(js|css|xml|gz|newone)$">

+0

tôi thêm mã vào file .htaccess của tôi, nhưng tôi trang web vẫn không gzipped những gì wront bạn có thể giúp .. tôi liên lạc với công ty lưu trữ của tôi và họ là một loạt các idiots nói htaccess shouldnt được trong thư mục gốc của trang web ở nơi đầu tiên !!! crazy – jshariar

+0

Tôi không biết vấn đề gì. Bạn nên chèn mã vào một [.htaccess] rỗng (http://en.wikipedia.org/wiki/Htaccess) (phải nằm trong cùng thư mục với tệp index.html/index.php). Có lẽ nó sẽ hoạt động và bạn có thể tìm ra vấn đề là gì. Hãy thử [công cụ này] (http://tools.pingdom.com/fpt/) để kiểm tra nén. Có thể bộ nhớ đệm của trình duyệt gây ra một số vấn đề. –

+0

Có lỗi đánh máy trong mã của bạn - bạn cần dấu hai chấm sau 'Vary': 'Header append Vary: Accept-Encoding' – fastasleep

3

Tôi cũng đã có vấn đề với điều này không làm việc

Wht xảy ra là tôi đã có một chỉ thị tiêu đề cho file php của tôi

Tôi có một Header thiết lập Cache-control - và nó ghi đè append Tiêu đề Vary, vì vậy bạn phải đặt chúng trong cùng một khối.
Những gì tôi phải làm là thiết lập các Vary cho tất cả các file khác trong một tuyên bố FilesMatch và Cache và Vary cho các tập tin php trong một tuyên bố FilesMatch riêng biệt như thế này:

<IfModule mod_headers.c> 
<FilesMatch "\.(js|css|gz)$"> 
Header append Vary: Accept-Encoding 
</FilesMatch> 
</IfModule> 


<IfModule mod_headers.c> 
<FilesMatch "\.(php)$"> 
Header set Cache-Control "max-age=300" 
Header append Vary: Accept-Encoding 
</FilesMatch> 
</IfModule> 

Đó không phải là thực tế Cache- của tôi Câu lệnh điều khiển - chỉ đơn giản hóa cho mã ví dụ.

17

Tôi nhận được gần 100 điểm% trong https://tools.pingdom.com/https://developers.google.com/speed/pagespeed/insights/

Tôi tìm thấy một bài hữu ích để tăng tốc độ website wordpress hoặc blog https://www.keycdn.com/blog/speed-up-wordpress/

Với một số tối ưu hóa khác, tôi cũng đang sử dụng bên dưới mã trên trang web của tôi trong .htaccess tập tin (thường ẩn trong thư mục trang web chính)

máy chủ của tôi là Apache, bạn có thể kiểm tra trong lưu trữ bảng điều khiển (Giống như cPanel/WHM panel) (nếu máy chủ của bạn là kiểm tra nginx keycdn.com bưu điện)

(Sao chép và dán mã dưới đây trong tập tin .htaccess, nó làm việc tốt cho tôi)

(Upvote câu trả lời này nếu tác phẩm cho bạn)

<IfModule mod_expires.c> 
ExpiresActive On 
ExpiresByType image/jpg "access 1 month" 
ExpiresByType image/jpeg "access 1 month" 
ExpiresByType image/gif "access 1 month" 
ExpiresByType image/png "access 1 month" 
ExpiresByType image/svg "access 1 month" 
ExpiresByType text/css "access 1 month" 
ExpiresByType text/html "access 1 month" 
ExpiresByType application/pdf "access 1 month" 
ExpiresByType text/x-javascript "access 1 month" 
ExpiresByType text/javascript "access 1 month" 
ExpiresByType application/javascript "access 1 month" 
ExpiresByType application/xhtml+xml "access 1 month" 
ExpiresByType application/x-shockwave-flash "access 1 month" 
ExpiresByType image/x-icon "access 1 month" 
ExpiresDefault "access 1 month" 
</IfModule> 

<ifModule mod_headers.c> 
    <filesMatch ".(css|jpg|jpeg|png|gif|swf|svg|js|ico)$"> 
    Header set Cache-Control "max-age=2592000, public" 
    </filesMatch> 
    <filesMatch ".(x?html?|php)$"> 
    Header set Cache-Control "private, must-revalidate" 
    </filesMatch> 
</ifModule> 

<IfModule mod_deflate.c> 
    # Compress HTML, CSS, JavaScript, Text, XML and fonts 
    AddOutputFilterByType DEFLATE application/javascript 
    AddOutputFilterByType DEFLATE application/json 
    AddOutputFilterByType DEFLATE application/atom+xml 
    AddOutputFilterByType DEFLATE application/rdf+xml 
    AddOutputFilterByType DEFLATE application/rss+xml 
    AddOutputFilterByType DEFLATE application/vnd.ms-fontobject 
    AddOutputFilterByType DEFLATE application/x-font 
    AddOutputFilterByType DEFLATE application/x-font-opentype 
    AddOutputFilterByType DEFLATE application/x-font-otf 
    AddOutputFilterByType DEFLATE application/x-font-truetype 
    AddOutputFilterByType DEFLATE application/x-font-ttf 
    AddOutputFilterByType DEFLATE application/x-font-woff 
    AddOutputFilterByType DEFLATE application/x-javascript 
    AddOutputFilterByType DEFLATE application/xhtml+xml 
    AddOutputFilterByType DEFLATE application/xml 
    AddOutputFilterByType DEFLATE font/opentype 
    AddOutputFilterByType DEFLATE font/otf 
    AddOutputFilterByType DEFLATE font/truetype 
    AddOutputFilterByType DEFLATE font/ttf 
    AddOutputFilterByType DEFLATE image/svg+xml 
    AddOutputFilterByType DEFLATE image/x-icon 
    AddOutputFilterByType DEFLATE text/css 
    AddOutputFilterByType DEFLATE text/html 
    AddOutputFilterByType DEFLATE text/javascript 
    AddOutputFilterByType DEFLATE text/plain 
    AddOutputFilterByType DEFLATE text/xml 
</IfModule> 
+0

Điều này đã cho tôi từ một C -> B (trên số liệu tiêu đề trang) ... bây giờ nhận được thông tin về cách sử dụng cookie (mặc dù tôi có một ứng dụng đơn giản .. tiếp tục quay số .. nhưng điều này đã giúp tôi rất nhiều!) – natureminded

Các vấn đề liên quan