What is the best method to reduce the size of my J

2019-01-07 11:09发布

When working with large and/or many Javascript and CSS files, what's the best way to reduce the file sizes?

18条回答
beautiful°
2楼-- · 2019-01-07 11:27

I'd give a test-drive to the new runtime optimizers in ASP.Net published on http://www.codeplex.com/NCOptimizer

查看更多
我命由我不由天
3楼-- · 2019-01-07 11:28

Rather than tweaking your files directly, I would recommend compressing them. Most clients support it.

I think you'll find that this is easier and just as effective.

More details from Jeff's adventures with it.

查看更多
太酷不给撩
4楼-- · 2019-01-07 11:29

YUI Compressor has my vote, for the simple reason that instead of just performing regular expression transformations on the code, it actually builds a parse tree of the code, similar to a Javascript interpreter, and then compresses it that way. It is usually very careful about how it handles the compression of identifiers.

Additionally it has a CSS compression mode, which I haven't played with as much.

查看更多
ゆ 、 Hurt°
5楼-- · 2019-01-07 11:31

Here are the online tools by which you can do this:-

  • For HTML, CSS or JS minifier, you can use https://cssminifiers.com. This is currently best css minigier/un-minifier
  • For compress your HTML, CSS or JS, you can use http://www.htmlminifier.com/ online tool.
  • And also you can use http://javascript-minify.com online tool to minify you JS.

Above are the tools which I seems to be useful for you.

查看更多
Evening l夕情丶
6楼-- · 2019-01-07 11:31

CssTidy is the best CSS optimizer of which I am aware. It (configurably) strips comments, eliminates whitespaces, rewrites to use the many shorthand rules nickf mentioned, etc. Compressing the result helps too, as others have mentioned.

The compression ratio can be fairly dramatic, and it frees you to comment your CSS extensively without worrying about the file size.

Unfortunately, this level of preprocessing interacts with some of the popular "css hacks" in unpredictable (or predictable but undesired) ways. Some work, some don't, and some require configuration settings which reduce the level of compression for other things (especially comments).

查看更多
走好不送
7楼-- · 2019-01-07 11:35

Dojo Shrinksafe is a Javascript compressor that uses a real JS interpreter, so it won't break your code. The other ones can work well, but Shrinksafe is a good one to use in a build script, since you shouldn't have to re-test the compressed script.

查看更多
登录 后发表回答