简体   繁体   English

谷歌样式表编译器CSS重命名

[英]google stylesheet compiler CSS renaming

Currently, I'm using Closure Compiler just on the javascript file. 目前,我仅在javascript文件上使用Closure Compiler。 Now I also want to minify and rename the CSS classes with shorter names. 现在,我还要缩小名称,并用较短的名称重命名CSS类。

Is there a way to avoid having to rewrite every jquery CSS string-based selector in my .js file (ie. $('#SomeID') or $('.SomeClass')) to a variable-based selector? 有没有一种方法可以避免不得不将我的.js文件中的每个基于jQuery CSS字符串的选择器(即$('#SomeID')$('.SomeClass'))重写为基于变量的选择器? Since most of the HTML is actually generated at runtime, I could easily moved the skeleton HTML that's initially in the page to the .js file and have the document.ready function first put the skeleton HTML needed for the app on the page. 由于大多数HTML实际上是在运行时生成的,因此我可以轻松地将页面中最初的框架HTML移到.js文件中并拥有document.ready函数,然后将应用程序所需的框架HTML首先放在页面上。 Would that avoid the rewriting of the CSS selectors or would the selectors still need to be rewritten as properties of an object? 这样做会避免重写CSS选择器,还是仍然需要将选择器作为对象的属性进行重写?

The doc is here but I didn't find it clear http://code.google.com/p/closure-stylesheets/#Renaming 该文档在这里,但我找不到清晰的http://code.google.com/p/closure-stylesheets/#Renaming

Thanks for your suggestions. 感谢您的建议。

The short answer to your question is "no there isn't". 对于您的问题的简短回答是“不存在”。

Given that you've specified that you're using jQuery selectors here, we can see that any tool for this job would need to rewrite your all three of your HTML, CSS and JS code. 假设您已在此处指定使用jQuery选择器,我们可以看到该作业的任何工具都需要重写HTML,CSS和JS代码中的所有三个。

The JS code in particular will be very tricky, because of the possibility of building the jQuery selectors using substrings - eg $('#prefix_' + suffix) . JS代码特别棘手,因为可以使用子字符串构建jQuery选择器,例如$('#prefix_' + suffix) I don't know if you've done that kind of thing or not, but the ability to do it makes it virtually impossible to write a completely reliable tool that can rename your IDs and classes, but still have your JS code work correctly. 我不知道您是否做过这种事情,但是这样做的能力使编写一个完全可靠的工具(可以重命名ID和类,但仍使JS代码正常工作)几乎是不可能的。 If your code is relatively simple, it may be possible to write it so that it would work for you, but no-one is going to release a tool for general use that would break so easily. 如果您的代码相对简单,则可以编写它以便对您有用,但是没有人会发布一种通用的工具,这种工具很容易损坏。

In addition, I don't believe that such a tool would be particularly useful. 另外,我认为这样的工具不会特别有用。 It sounds like a case of excessive optimisation. 这听起来像是过度优化的情况。

Optimisation is great -- it's good to make an effort to make your site as fast as possible. 优化很棒-努力使您的网站尽可能快是一件好事。 But one of the key arts of good optimisation is to optimise the areas where you are slowest . 但是,良好优化的关键技巧之一就是优化您最慢的区域 I would be extremely surprised if the major bottleneck in your code is the length of your class names. 如果您代码中的主要瓶颈是类名的长度,我将感到非常惊讶。

My advice therefore is to spend your time finding out where the real bottlenecks are in your code, and deal with those. 因此,我的建议是花时间找出真正的瓶颈在代码中的位置,并加以解决。 The effect is likely be far greater than all the minification efforts you've done in total so far. 效果可能远远超过您到目前为止完成的所有缩小工作。

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

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