zoukankan      html  css  js  c++  java
  • 修改.htaccess文件提升网站访问速度方法

    简单点说:就是缓存一下不常修改的文件,提升访问速度。再简单点说:就是在.htaccess文件中写入以下内容。

    有时候遇到一个比较复杂的问题,我会选择暂时放一放。

    YSlow的检测结果,当时优化掉几个问题后,就暂时放手了。

    最近在网站优化上有了新的认识,应用一下:

    1. Add an Expires or a Cache-Control Header

      简单点说:就是缓存一下不常修改的文件,提升访问速度。
      再简单点说:就是在.htaccess文件中写入以下内容:

      <IfModule mod_expires.c>
      ExpiresActive On
      ExpiresDefault A600
      ExpiresByType image/x-icon A2592000
      ExpiresByType application/x-javascript A2592000
      ExpiresByType text/css A604800
      ExpiresByType image/gif A2592000
      ExpiresByType image/png A2592000
      ExpiresByType image/jpeg A2592000
      ExpiresByType text/plain A86400
      ExpiresByType application/x-shockwave-flash A2592000
      ExpiresByType video/x-flv A2592000
      ExpiresByType application/pdf A2592000
      ExpiresByType text/html A600
      </IfModule>

      text/css之类代表文件类型,A2592000表示在浏览器中的缓存时间,2592000秒=30天。

    2. Gzip components

      Gzip压缩是减少文件体积增加用户体验的简单方法,
      同样,添加以下代码到.htaccess文件即可。

      <ifmodule mod_deflate.c>
      AddOutputFilter DEFLATE html xml php js css
      </ifmodule>

    3. 配置ETag

      这段话我没看明白,总之结论是:如果你没有使用ETag提供的灵活的验证模式,那么干脆把所有的ETag都去掉会更好。

      我的网站只放在一台服务器上,我写.htaccess关了它:

      FileETag none

  • 相关阅读:
    git 删除已经提交的文件
    IDEA不显示service 服务窗口
    MySQL SQL语句查询结果 多列合并为1列
    Linux远程执行脚本
    mycat 连接命令
    win10 关闭被占用的端口
    ERROR 1045 (HY000): Access denied for user 'root', because password is error
    unblock with 'mysqladmin flush-hosts'
    neo4j数据库cypher查询
    基于websocket的网页实时消息推送与在线聊天(上篇)
  • 原文地址:https://www.cnblogs.com/derrck/p/1552868.html
Copyright © 2011-2022 走看看