为什么人们缩小资产而不是HTML? [英] Why people minify assets and not the HTML?

查看:149
本文介绍了为什么人们缩小资产而不是HTML?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么人们建议缩小网站资产(如CSS和JavaScript),但他们从不建议缩减标记? CSS和JavaScript可以在许多不同的页面上使用,而标记每次都会被加载,从而使得标记的缩小更为重要。

一个可能的原因是标记通常会更频繁地变化很多,并且必须在每次页面加载时缩小标记。例如,在给定的Stack Overflow页面上,有时间戳,用户名和代表计数可能随着每次页面加载而改变,这意味着您也必须为每个页面加载进行缩减。使用像CSS和JavaScript这样的静态文件,你可以缩短更少的时间,所以在某些人看来,这是值得的。



还要考虑到,每个主要的Web服务器和浏览器都支持gzip,它可以随时压缩所有标记( )。由于缩小速度比gzipping慢,效果也比gzipping低很多,网站管理员可能会认为缩小每个页面负载不值得处理成本。


Why do people suggest minifying web assets, such as CSS and JavaScript, but they never suggest the markup be minified? CSS and JavaScript can be used on many various pages while the markup gets loaded each and every time, making minification of markup far more important.

解决方案

One likely reason is that markup typically changes MUCH more often, and would have to be minified for every page load. For instance on a given Stack Overflow page, there are timestamps, usernames, and rep counts that could change with every page load, meaning you would have to minify for each page load as well. With "static" files like css and javascript, you can minify far less often, so in the minds of some, it is worth the work up front.

Consider also that every major web server and browser support gzip, which compresses all of your markup (quickly) on the fly anyway. Because minifying is slower and much less effective than gzipping anyway, webmasters may decide that minifying for every page load isn't worth the processing cost.

这篇关于为什么人们缩小资产而不是HTML?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆