简体   繁体   English

如何在Zend Framework中“gzip”我的回复?

[英]How do I “gzip” my responses in Zend Framework?

I know that this bit of code: 我知道这段代码:

<?php if (substr_count($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip')) ob_start("ob_gzhandler"); else ob_start(); ?>

will enable gzip. 将启用gzip。 But, what is the correct way to apply this to all my Zend Frameworks View s and Layout s? 但是,将这个应用到我所有的Zend Frameworks ViewLayout的正确方法是什么?

Instead of gzipping from PHP (which means only your HTML generated content will be compressed) , you could ask Apache to compress for you -- using its mod_deflate module. 而不是从PHP中删除(这意味着只会压缩您生成的HTML内容) ,您可以要求Apache为您压缩 - 使用其mod_deflate模块。

Great advantage : it'll allow your server to compress HTML, of course... But also JS and CSS ; 很大的优势:它会让你的服务器压缩HTML,当然......还有JS和CSS; which means a huge gain for the users who have to download those when visiting your site. 这意味着在访问您的网站时必须下载这些用户的用户将获得巨大收益。


Note : if you are not using Apache, other web-servers have equivalents of mod_deflate ;-) 注意:如果您不使用Apache,其他Web服务器具有mod_deflate等价物;-)

This blog post should help you with what you need. 这篇博客文章可以帮助您满足您的需求。

Queued, Concatenated, and Gzipped Assets with the Zend Framework 使用Zend Framework进行排队,连接和Gzipped资产

That piece of code will still work on Zend Framework, it's what I use. 这段代码仍然适用于Zend Framework,这就是我使用的。 Also, you don't need to check for the accept gzip header since ob_gzhandler() checks for that anyway. 此外,您不需要检查accept gzip标头,因为ob_gzhandler()无论如何都会检查它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM