开发者

compress html code

Just a quick ques开发者_JAVA技巧tion, I have seen some web page if I click view page source, the html code is compressed, if I want my html code to be compressed like that, is there a function doing the compression or I need to use come compress tool to do it before the webpage is loaded on line? Thanks a lot.


I'm not a PHP/*nix guy, but since we have been chatting about it in comments, check these..

For PHP:

  • http://davidwalsh.name/compress-xhtml-page-output-php-output-buffers

For Apache:

  • http://perl.apache.org/docs/1.0/guide/modules.html#Apache_GzipChain__compress_HTML__or_anything__in_the_OutputChain

  • http://betterexplained.com/articles/how-to-optimize-your-site-with-gzip-compression/

Check this discussion as well:

  • http://forums.macnn.com/79/developer-center/276604/compressing-html-output-with-php/


There are tools available for that purpose, basically these tools remove blank lines from the html code. Search for html optimizer or blank space remover tools on google and you'll find many easily.

If you are using j2ee, there are filter available (as jars), which you can download and edit your web.xml file to use them. They will remove the blank spaces when the page is being displayed.


If for "compressed" you mean without whitespaces, without line breaks, without tabs, etc, yes, there exist tools that could do the job for you, although it would be easy to write a personalized script.

By example, see this script. Here you have the live demo.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜