We don’t allow questions seeking recommendations for software libraries, tutorials, tools, books, or other off-site resources. You can edit the question so it can be answered with facts and citations.
Closed 8 years ago.
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(8)
“缩小” HTML 或 CSS 是非常困难的,因为所有可以安全保存的都是空白(这并不意味着巨大的节省)。至于类重命名,您失去了网络的一个重要部分,它具有语义代码(代表含义)。我认为最好的选择是确保您的 Web 服务器上启用了 gzip 压缩,并尽可能将您的资源合并到单个文件中。
It is very difficult to 'minify' HTML or CSS because all that can safely be saved is white space (which doesn't amount to a huge saving). As for class renaming, you loose an important part of the web which is having semantic code (which represents meaning). I think the best option is to ensure that you have gzip compression enabled on your web server and focus on combining your assets into a single file wherever possible.
HTML Muncher 是一个 Python 工具,它尝试跨 HTML、javascript 和 CSS 文件重命名 ID 和 CSS 类名称。在将文件传递给其他工具(例如 Google Closure Compiler 或 YUI CSS Compressor)之前,您可以将其用作优化过程的第一步。
HTML Muncher is a python tool that tries to rename IDs and CSS class names across HTML, javascript and CSS files. You can use it as a first step in your optimization process, before passing the files to other tools such as Google Closure Compiler or YUI CSS Compressor.
YUI 压缩器缩小了CSS,但我不确定它有多大的胜利可能是简单的 gzip 压缩。如果你有那么多 CSS,这可能是更大问题的警告信号。
The YUI Compressor minifies CSS, but I'm not sure how big a win it might be over simple gzip compression. If you have that much CSS, it might be a warning sign of bigger problems.
看看这个: minifycss
至于混淆,我不确定这是一个好主意。
css 类可以在任何地方进行操作。一旦你改变CSS,你就会失去类/ID等的链接......
Take a look at this: minifycss
As for obfuscation I am not sure that this is such a good idea.
The css classes can be manipulated anywhere. The minute you change the css you will lose the link to the classes/ids etc...
如果您使用 Ruby,这里有一个 Ruby CSS Minifier,我用它效果很好。鉴于我已经很简洁的风格,它使我的文件大小减少了约 15%。
例如,在一个项目中,5 个 32.3kiB 文件的总和变为 1 个 26.4kiB 文件(18%)。在另一个项目中,2 个 21.6kiB 的文件变成了 1 个 19.0kiB 的文件(12%)。
If you use Ruby, here is a Ruby CSS Minifier that I use to good effect. Given my already-terse style, it gives me about 15% reduction in my file sizes.
For example, on one project the aggregate of 5 files at 32.3kiB becomes 1 file of 26.4kiB (18%). On another project, 2 files of 21.6kiB become 1 file of 19.0kiB (12%).
看看 html5boilerplate.com;特别是 GitHub 上的最新源代码。
HTML5Boilerplate 的构建脚本可以为您缩小 JavaScript、CSS 和 HTML。它不会重命名您的 CSS 选择器,但它可能是您能找到的最接近自动“混淆器”的。
如果您只是想从每个页面中找出一些额外的字节,请确保您使用的是 gzip/deflate 压缩,然后尝试按字母顺序排列 CSS 选择器属性和 HTML 元素的属性及其值。
阅读本文,了解 Google 关于上述方法的详细建议。
在某些带有 HTML 帮助程序的动态语言中(例如 asp.net/C#),您可以将 html 控件的“ClientID”方法覆盖为随机字符串,并将 CSS 选择器动态链接到 HTML(嗯,渲染的服务器端控件) HTML)。但这完全是另一个问题,而且可能不是您想要讨论的问题。这也将成为维护的噩梦。
Take a look at html5boilerplate.com; specifically the latest source-code on GitHub.
HTML5Boilerplate's build script can minify JavaScript, CSS, and HTML for you. It doesn't rename your CSS selectors but it is probably the closest to an automated "obfuscator" you will find.
If you are just looking to eek out some additional bytes from each page make sure you are using gzip/deflate compression and THEN try alphabetizing your CSS selector properties and your HTML element's attributes and their values.
Read this for Google's detailed recommendations on the above method.
In some dynamic languages with HTML helpers (like asp.net/C#) you can overwrite the html-control's "ClientID" method to be a random string and dynamically link your CSS selectors to your HTML (well, the server-side controls that render HTML). But that would be for another question entirely and is likely not what you are looking to get into. It would also become a maintenance nightmare.
有许多在线工具可以用于诸如 CSS 缩小之类的事情。这是一个在线 css 压缩器!我发现了。
至于重命名 css 类,我会尽力避免这种情况,因为你会失去 html 的很多可读性。
There are many online tools you can use for things like css minification. Here is an online css minifier! I found.
As for renaming css classes, I would try and avoid that as you will lose a lot of the readability from your html.
我开发了用于混淆 CSS 的工具。它的目标不是使样式表加载得更快或其他什么,而是使您的“可重用”工作安全不被窃取。它有几种方法来获取原始 CSS 源(但它仍在开发中,将使用更好的方法)。我会把它推荐给 HTML/CSS 模板卖家,他们提供现场演示并担心被盗,也推荐给编码员 - 自由职业者,他们想要向(不信任的)客户展示他们的工作。您可以尝试一下:http://cssobfuscator.com
I have developed tool for Obfuscating CSS. It's target is not to make stylesheets load faster or whatever, but to make your "reusable" work safe from stealing. It has several methods how to make a hell of getting an original CSS source (But it's still in development and better methods will be used). I would reccomend it to HTML/CSS templates sellers, who provide live demos and are worried of thefts, and also for coders - freelancers, who wants to present their work to (untrusty) customers. You can try it: http://cssobfuscator.com