• <mark id="61bqy"></mark>
    <menuitem id="61bqy"></menuitem>

    <small id="61bqy"></small>
    <menuitem id="61bqy"></menuitem><small id="61bqy"></small>
  • <tr id="61bqy"><small id="61bqy"></small></tr>

    <output id="61bqy"></output>
    <tr id="61bqy"><small id="61bqy"><acronym id="61bqy"></acronym></small></tr>

    <menuitem id="61bqy"><acronym id="61bqy"></acronym></menuitem>
    <code id="61bqy"></code>

    如何设置静态内容缓存时间

    时间:2014-06-21 来源:天津文率科技有限公司

    其实设置静态内容缓存时间就是让网页里的图片还有js、css这些资源、包括页面缓存到本地而不是每次都去服务器请求资源,这样做可以减轻服务器的带宽压力和使网页打开速度加快,这样以来用户体验就会好了一些,对seo是有好处的。

    那么如何来设置缓存时间呢?下面我就以apache为例吧,因为我们的官网用的是php+apache的,所以小韩就拿apache来说了

    本文关键词:gzipcache-expire

    用.htaccess设置网页/图片/js/css文件内容缓存

    开启gzip的方法:

    1、 http.conf下
    将#去掉
    LoadModule deflate_module modules/mod_deflate.so
    添加如下设置:
    <IfModule mod_deflate.c>
    <Location />
    #Insert filter
    SetOutputFilter DEFLATE
    # Netscape 4.x has some problems…
    BrowserMatch ^Mozilla/4 gzip-only-text/html
    # Netscape 4.06-4.08 have some more problems
    BrowserMatch ^Mozilla/4\.0[678] no-gzip
    # MSIE masquerades as Netscape, but it is fine
    # BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
    # NOTE: Due to a bug in mod_setenvif up to Apache 2.0.59
    # the above regex won’t work. You can use the following
    # workaround to get the desired effect:
    # BrowserMatch \bMSIE !no-gzip !gzip-only-text/html force-gzip
    BrowserMatch \bMSIE !no-gzip !gzip-only-text/html

    # Don’t compress images and other
    SetEnvIfNoCase Request_URI .(?:gif|jpe?g|png)$ no-gzip dont-vary
    SetEnvIfNoCase Request_URI .(?:exe|t?gz|zip|bz2|sit|rar)$ no-gzip dont-vary
    SetEnvIfNoCase Request_URI .(?:pdf|doc)$ no-gzip dont-vary
    AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css
    AddOutputFilterByType DEFLATE application/x-javascript
    # Make sure proxies don’t deliver the wrong content
    Header append Vary User-Agent env=!dont-vary

    #DeflateFilterNote ratio ratio_info
    #LogFormat ‘”%v %h %l %u %t “%r” %>s %b “%{Referer}i” “%{User-Agent}i”” (%{ratio}n)’ deflate
    #CustomLog logs/deflate_log deflate
    </Location>
    保存退出。重新启动apache就生效了

    2 开启cache-expire

    第1步
    LoadModule expires_module modules/mod_expires.so
    LoadModule expires_module modules/mod_headers.so
    在httpd.conf中,找到上面的代码,然后将前面的#去掉

    第2步
    在httpd.conf中加入以下代码,可以加到任何空白地方,不了解apache的朋友,如果担心加错地方,就放到http.conf文件的最后一行

    <IfModule mod_expires.c>

    ExpiresActive On

    ExpiresByType image/gif A2592000

    ExpiresByType image/jpeg A2592000

    ExpiresByType image/png A2592000

    ExpiresByType image/x-icon A2592000

    ExpiresByType application/x-javascript A604800

    ExpiresByType text/css A604800

    </IfModule>
    如果apache无法启动了,检查下是不是权限受了影响,因为如果访问权限设置的不对的话会报错,具体可以查看apche的日志,然后百度去找问题根源了。

    在开发过程中会有各种想不到的问题出现,这时我建议大家多百度和谷歌一下。

    好啦

    不早啦,明天我们天津网站建设公司-文率科技来讲讲如何用压缩js和css代码。

    更多网站建设方面的知识请关注我们的官网 www.rawai-rentals.com


    联络方式:

    中国 · 天津市河西区南京路35号亚太大厦1403室
    电话:15620613686
    邮编:300220

    国产精成品视频

  • <mark id="61bqy"></mark>
    <menuitem id="61bqy"></menuitem>

    <small id="61bqy"></small>
    <menuitem id="61bqy"></menuitem><small id="61bqy"></small>
  • <tr id="61bqy"><small id="61bqy"></small></tr>

    <output id="61bqy"></output>
    <tr id="61bqy"><small id="61bqy"><acronym id="61bqy"></acronym></small></tr>

    <menuitem id="61bqy"><acronym id="61bqy"></acronym></menuitem>
    <code id="61bqy"></code>