admin管理员组文章数量:1350483
Recently I've started using Grunt and it really helped to minify/concatenate .css files and minify/uglify/concatenate .js files. Also I automated piling and restarting server with grunt watch, express. I was happy.
Suddenly I wanted to uglify my .css files when I saw 85 occurrences of ".wrapper" class in my style.css. This .wrapper
class used in my templates (jQuery.tmpl), .js files. I've seen uglified .css classes in gmail source code and I hope I can do it too.
My purpose is to replace '.wrapper' with '.w' (any short name) in all .css, .html, .js files. How can I uglify all class
es, id
s in .js, .html, .css files relatively?
Recently I've started using Grunt and it really helped to minify/concatenate .css files and minify/uglify/concatenate .js files. Also I automated piling and restarting server with grunt watch, express. I was happy.
Suddenly I wanted to uglify my .css files when I saw 85 occurrences of ".wrapper" class in my style.css. This .wrapper
class used in my templates (jQuery.tmpl), .js files. I've seen uglified .css classes in gmail source code and I hope I can do it too.
My purpose is to replace '.wrapper' with '.w' (any short name) in all .css, .html, .js files. How can I uglify all class
es, id
s in .js, .html, .css files relatively?
- there are many different solutions built nowadays... Maybe you should read this topic: stackoverflow./questions/28932/best-javascript-pressor hope it help. – Carlos Commented Jan 27, 2014 at 19:04
-
He's asking about CSS uglification though, not JS. @bob The problem with obfuscating (uglifying) CSS is that you also have to capture any HTML uses of those classes or IDs and any uses in JavaScript code. If you simply press the CSS file to use
.w
instead of.wrapper
but don't change all HTML files using.wrapper
then your site will break. I don't know of an easy solution to this problem with a basic Grunt task. – Jordan Kasper Commented Jan 27, 2014 at 20:47 - @jakerella I've removed gruntjs tag. I want to know any method or tool to uglify my .css file along with .js, .html files. – Ikrom Commented Jan 28, 2014 at 16:09
- I haven't tested it, but this might do the trick? github./yiminghe/grunt-class-id-minifier – Kristof Feys Commented Jan 28, 2014 at 16:14
- @KristofFeys Good job! I've tried and it uglified .html file. But it could not uglified .css file pletely. Only uglified the most outer class names in .css file. So far it's not usable. – Ikrom Commented Jan 28, 2014 at 17:02
1 Answer
Reset to default 7There are 2-3 processes at work when you "uglify" something:
- Minification - Eliminates unnecessary whitespace in your text files.
- Obfuscation - Where you rename variables, classes, etc. into smaller names to save characters.
- Concatenation - Where you merge multiple files together to eliminate unnecessary HTTP requests.
It looks like you're primarily talking about obfuscation so that's what I'll address. There are two tools that I know of that work pretty well and can be used in a build process:
HTML Muncher - HTML Muncher is a 5 year old Python based tool. It can only deal with HTML, CSS, and JS files so you'll have to pile your static assets before shipping it over to this Python based tool. Also, it doesn't work well with escaped class/id names or special characters (so keep yours alpha based and only use digits after the first alpha character). Finally, it obfuscates names based off of a hashid.. so the class names aren't as succinct as you'll want them.
The css-loader is used as a part of Webpack - Webpack allows us to use loaders to transform files and pass them in as dependencies in front-end "bundles". The css-loder has this cool feature called Local Scope that essentially allows you to rename your classes and id's based on your webpack config. Webpack can be difficult to setup and it's pretty difficult (at the time of this writing) to get these obfuscated class names into HTML files. But if you can get it working and make it a part of your build, I think this tool has a lot of promise!
At this time, I'd say that if you can't make Webpack a part of your build, it's probably not worth obfuscating your CSS at this time unless you can handle all the problems that HTML Muncher has.
本文标签: javascriptUglify entire project (cssJShtml files relatively)Stack Overflow
版权声明:本文标题:javascript - Uglify entire project (.css, .js, .html files relatively) - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743876197a2554368.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论