开发者

How do I "gzip" my responses in Zend Framework?

I know that this bit of code:

<?php if (substr_count($_SERVER['HTTP_A开发者_高级运维CCEPT_ENCODING'], 'gzip')) ob_start("ob_gzhandler"); else ob_start(); ?>

will enable gzip. But, what is the correct way to apply this to all my Zend Frameworks Views and Layouts?


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.

Great advantage : it'll allow your server to compress HTML, of course... But also JS and 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 ;-)


This blog post should help you with what you need.

Queued, Concatenated, and Gzipped Assets with the Zend Framework


That piece of code will still work on Zend Framework, it's what I use. Also, you don't need to check for the accept gzip header since ob_gzhandler() checks for that anyway.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜