- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
YSlow 告诉我我的 css 应该被压缩,但经过几个小时的修补后,我一辈子都无法让 gzip 为我的网站工作。此时,我什至不确定性能提升是否值得(会有吗?)。
我在 1&1 共享托管帐户上运行 WordPress 网站。
老实说,我真的不知道我在用这些东西做什么,而且似乎无法获得适当的设置。我在一些地方读到 1&1,“模块 Apache mod_deflate 和 mod_gzip 未安装。”,所以我认为这是问题的一部分。
我尝试了以下代码:
这个似乎没有做任何事情:
<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>
这会导致 500 错误
<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
# Don't compress images
SetEnvIfNoCase Request_URI \
\.(?:gif|jpe?g|png)$ no-gzip dont-vary
# Make sure proxies don't deliver the wrong content
Header append Vary User-Agent env=!dont-vary
</Location>
这(来自 html5 样板)似乎也没有做任何事情:
<IfModule mod_deflate.c>
# Force deflate for mangled headers developer.yahoo.com/blogs/ydn/posts/2010/12/pushing-beyond-gzipping/
<IfModule mod_setenvif.c>
<IfModule mod_headers.c>
SetEnvIfNoCase ^(Accept-EncodXng|X-cept-Encoding|X{15}|~{15}|-{15})$ ^((gzip|deflate)\s*,?\s*)+|[X~-]{4,13}$ HAVE_Accept-Encoding
RequestHeader append Accept-Encoding "gzip,deflate" env=HAVE_Accept-Encoding
</IfModule>
</IfModule>
# HTML, TXT, CSS, JavaScript, JSON, XML, HTC:
<IfModule filter_module>
FilterDeclare COMPRESS
FilterProvider COMPRESS DEFLATE resp=Content-Type $text/html
FilterProvider COMPRESS DEFLATE resp=Content-Type $text/css
FilterProvider COMPRESS DEFLATE resp=Content-Type $text/plain
FilterProvider COMPRESS DEFLATE resp=Content-Type $text/xml
FilterProvider COMPRESS DEFLATE resp=Content-Type $text/x-component
FilterProvider COMPRESS DEFLATE resp=Content-Type $application/javascript
FilterProvider COMPRESS DEFLATE resp=Content-Type $application/json
FilterProvider COMPRESS DEFLATE resp=Content-Type $application/xml
FilterProvider COMPRESS DEFLATE resp=Content-Type $application/xhtml+xml
FilterProvider COMPRESS DEFLATE resp=Content-Type $application/rss+xml
FilterProvider COMPRESS DEFLATE resp=Content-Type $application/atom+xml
FilterProvider COMPRESS DEFLATE resp=Content-Type $application/vnd.ms-fontobject
FilterProvider COMPRESS DEFLATE resp=Content-Type $image/svg+xml
FilterProvider COMPRESS DEFLATE resp=Content-Type $image/x-icon
FilterProvider COMPRESS DEFLATE resp=Content-Type $application/x-font-ttf
FilterProvider COMPRESS DEFLATE resp=Content-Type $font/opentype
FilterChain COMPRESS
FilterProtocol COMPRESS DEFLATE change=yes;byteranges=no
</IfModule>
<IfModule !mod_filter.c>
# Legacy versions of Apache
AddOutputFilterByType DEFLATE text/html text/plain text/css application/json
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE text/xml application/xml text/x-component
AddOutputFilterByType DEFLATE application/xhtml+xml application/rss+xml application/atom+xml
AddOutputFilterByType DEFLATE image/x-icon image/svg+xml application/vnd.ms-fontobject application/x-font-ttf font/opentype
</IfModule>
</IfModule>
这个似乎没有做任何事情...
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css application/x-javascript
我按照此处找到的教程进行操作
(http://mrrena.blogspot.com/2009/01/how-to-compress-php-and-other-text.html)
但这基本上完全破坏了我网站的外观。
<小时/>在我的 Functions.php 中尝试过这个,它似乎压缩了我的 html,但留下了一些未压缩的 js 和 css
if(extension_loaded("zlib") && (ini_get("output_handler") != "ob_gzhandler"))
add_action('wp', create_function('', '@ob_end_clean();@ini_set("zlib.output_compression", 1);'));
最佳答案
所以,过了一段时间,我想出了如何压缩具有 1&1 Webhosting 包的 html、css 和 js 文件。不支持放气!
对于动态内容,您将 php.ini 添加到网站的根目录中。 php.ini内容:
zlib.output_compression =1
zlib.output_compression_level =9
当然你也可以选择其他压缩级别,9是最高的(并且导致最高的服务器负载)。这将压缩动态生成的 html 文件。
要压缩静态文件(css、js 和图像...),您需要修改 .htaccess 文件。对于该附加
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteOptions Inherit
ReWriteCond %{HTTP:accept-encoding} (gzip.*)
ReWriteCond %{REQUEST_FILENAME} !.+\.gz$
RewriteCond %{REQUEST_FILENAME}.gz -f
RewriteRule (.+) $1.gz [QSA,L]
</IfModule>
到您的 .htaccess 文件(您可以在网站的根目录中找到该文件 - 否则创建它)。但压缩不会自动完成。所以你必须自己压缩文件!使用例如7-zip 并用 .gz 压缩 js 和 css 文件 -> 结果应该是例如样式表.css.gz。然后将文件上传到与刚刚压缩的文件相同的目录中。
现在应该可以了!
PS:压缩并不总是有用,尤其是当文件非常小时。因此检查压缩前后的差异。
关于wordpress - 如何使 gzip 在 1and1 共享主机 WordPress 网站上工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11420992/
我创建了一个 View (称为 masterView),CGRect 的 x=160、y=186、width=1600、height=380。该 View 包含 5 个 subview ,每个 sub
我是 R 的新手,目前正在处理边缘列表形式的协作数据,该列表具有 32 列和大约 200.000 行。我想根据国家之间的相互作用创建一个(共)现矩阵。但是,我想通过对象的总数来计算交互次数。 期望结果
考虑以下发展: Require Import Relation RelationClasses. Set Implicit Arguments. CoInductive stream (A : Typ
我正在玩弄这种语言来开始学习,我对递归定义的工作原理感到困惑。 例如,让我们采用三角形数的序列(TN n = sum [1..n]) 提供的解决方案是: triangularNumbers = sca
我正在尝试获取“总分钟数”值中的 PHP“DateInterval”值。如何获得?似乎简单格式(“%i 分钟”)不起作用? 示例代码如下: $test = new \DateTime("48 hour
我有这个脚本可以通过电子邮件自动发送负载信息: if(confirm('', 'Are you sure?') == true) { // enviar mails var emails = new
我有一些数据要查询。该表由两列组成 - 一个唯一 ID 和一个值。我想计算每个唯一值出现的次数(这可以通过 COUNT 和 GROUP BY 轻松完成),但我希望能够对其进行计数。所以,我想看看有多少
当我在我的 Java 代码上运行 PMD 时,它显示的错误消息之一是“类 STWeb 具有 20 的圈复杂度”。通常我的java类是这样的 public class STWeb implements
尝试在打印时在页面底部显示第 1 页,共 10 页... 第 1 页,共 0 页 正在显示,因此计数器(页面)似乎无法正常工作。我正在使用 Chrome,所以 @pages { ... 也不起作用。有
我在尝试运行单元测试用例时收到 Executed 0 of 0 ERROR 错误。我遵循了针对此问题提到的几个解决方案,但我仍然遇到相同的错误。 尝试过: 删除 angular-scenario 文件
我们有一个应用程序,可以在运行时生成大约 100 个动画,并将它们全部添加到单个 Storyboard 中然后播放。问题是动画速度非常慢。进行动画处理的对象是形状和样条线,并且在后端完成大量计算以生成
我正在为数学演示编写凯撒加密代码。今天,我一直在为我的演讲编写代码。早上这个代码就开始工作了。但现在在学校,我遇到了一个异常(exception),我认为 for 超出了我的符号表的长度。 异常(ex
关闭。此题需要details or clarity 。目前不接受答案。 想要改进这个问题吗?通过 editing this post 添加详细信息并澄清问题. 已关闭 6 年前。 Improve th
我有一张带有 4 个标签的表格,效果很好。当我使用也能正常工作的搜索栏时,表格只显示两个标签: - (void)viewDidLoad { [super viewDidLoad]; NSS
我正在使用 iText 在我的 Java EE 应用程序中生成 PDF 文档。 PDF 文件的编码驻留在 JSP 中。 我想在每个页脚中实现以下页面格式, REF:XXXXXXX 第 X 页,共第 Y
我试图找出(出于好奇)哪个线程实际调用了单例构造函数。好吧,我完全理解每次执行测试程序时线程都会不同,只是想在实用上检查是否相同。我试过 dumpStack() printStackTrace() g
我在工作时遇到了一些麻烦。这可能真的很简单,但我让它变得比可能的更困难。所以我有一个包含 3 组 UL 的 div。 代码如下: content here content here c
我有一个问题,当网格为空时,为什么它显示 Page 1 of 0 不能是 Page 1 of 1 或更合理的东西吗? 我的代码 var xml=client.responseText;
我想将 Crashlytics 添加到我的项目中,我根据 Fabric Mac 应用程序制作了所有内容,现在我停留在 Step 2 of 2 when verifying installation 我
我正在使用 qt 从 html 代码生成一个 pdf 文件: QTextDocument *document = new QTextDocument(); document->setHtml(html
我是一名优秀的程序员,十分优秀!