1

我正在尝试提高我们的页面速度,建议使用 Connection: Keep-alive。但是,无论我尝试做什么,我都有“保持活力,关闭”。而且我找不到“关闭”值的来源。

我也不能删除它。有人经历过同样的事情吗?

我的 .htaccess 中有这个:

标头集连接保持活动

最好的问候,拉斯穆斯

4

1 回答 1

1

Your server appears to have keep-alive disabled for either your account or the whole server to ensure the maximum number of sockets are available at all times Rasmus.

This is of course a double edged sword because most websites typically make between 10-30 requests when pulling down all the resources needed to build a page providing nothing is cached, which is a lot of opening and closing overhead. Even if it needed to pull down 50 additional resources setting it like this:

<ifModule mod_headers.c>
    Header set Connection keep-alive
    Keep-Alive: timeout=5, max=100
</ifModule>

would be more then enough time to get the job done. But I'm sure it's standard practice to disable this feature in order to make sure it's not abused. Just ask your admin if they can hook you up.

My recommendation would be don't worry about the Keep-Alive header, you get way more bang for your buck by making sure your static files are being cached properly anyway. If your admin enables it for you down the road that's great but this is what I put in my .htaccess file to help reduce the number of requests it receives by 60%-80%.

<IfModule mod_expires.c>
    # 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"
</IfModule>
于 2014-05-26T11:30:12.057 回答