最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

JavaScript compression - Stack Overflow

programmeradmin0浏览0评论

I look for tool which can press JavaScript source code. I found some web tools which only deletes whitespace chars? But maybe exist better tool which can press user's function names, field name, deletes unused fields, others.

I look for tool which can press JavaScript source code. I found some web tools which only deletes whitespace chars? But maybe exist better tool which can press user's function names, field name, deletes unused fields, others.

Share Improve this question asked Sep 13, 2009 at 12:25 Michał ZioberMichał Ziober 38.7k18 gold badges109 silver badges151 bronze badges 4
  • There's very little purpose in pression or obfuscating JavaScript. What you describe would likely save you a few KB per user at best and not make it much more difficult to read the code. Why are you trying to do this? – chuckharmston Commented Sep 13, 2009 at 12:27
  • Multi Dup: stackoverflow./questions/883184/… – Crescent Fresh Commented Sep 13, 2009 at 13:39
  • I would do it, because 1)reduce the size of *.js files, 2)dotfuscate source code – Michał Ziober Commented Sep 13, 2009 at 13:45
  • 1 Also consider using google's code.google./closure/piler – Ruan Mendes Commented May 5, 2010 at 17:53
Add a ment  | 

3 Answers 3

Reset to default 9

A tool often used to press JS code is the YUI Compressor.

Considering there is this option :

--nomunge
    Minify only. Do not obfuscate local symbols.

It should be able to do what you asked.


And here is an article about it : Introducing the YUI Compressor.

Quoting that article :

It starts by analyzing the source JavaScript file to understand how it is structured. It then prints out the token stream, replacing all local symbols by a 1 (or 2, or 3) letter symbol wherever such a substitution is appropriate


As a sidenote : don't forget to gzip your JS/CSS files, when serving them from your webserver : this will reduce the size of data that goes through the network quite a lot !

For instance, if you are using Apache, take a look at mod_deflate.

Check out YUI Compressor, there is also ESC, but I suspect YUI is a bit better. Up to you to test.

Javascript minimizer have been discussed here before, but still I feel that the JavaScript pressor rater web page summarizes them best:

  • JSMin is a conservative pressor, written several years ago by Douglas Crockford. It is considered safe (especially if you verify your code with JSLint first-- an excellent thing to do anyway) because it doesn't attempt to change any variable names.
  • Dojo shrinksafe is a very popular Java based JavaScript pressor that parses the JavaScript using the rhino library and crunches local variable names.
  • Packer (Version 3.1) by Dean Edwards, is also a very popular JavaScript pressor, that can go beyond regular pression and also add advanced on-the-fly depression with a JavaScript runtime piece.
  • the YUI Compressor (Version 2.4.2) is a newer pressor written by Julien Lete, that aims to bine the safety of JSMin with the higher pression levels acheived by Dojo Shrinksafe. Like Dojo shrinksafe, it is written in Java and based on the rhino library.
发布评论

评论列表(0)

  1. 暂无评论