Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit da51013

Browse filesBrowse files
committed
update readme
1 parent 8a48bdd commit da51013
Copy full SHA for da51013

1 file changed

+22-4Lines changed: 22 additions & 4 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎README.md‎

Copy file name to clipboardExpand all lines: README.md
+22-4Lines changed: 22 additions & 4 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ Luckily, because the `'('` optimization for IIFEs is so well-established, we can
9797
parsing the entire JavaScript file in advance (a luxury the browser can't afford) and inserting parentheses in the cases where we _know_
9898
the function will be immediately executed (or where we have a good hunch). That's what `optimize-js` does.
9999

100+
More details on the IIFE optimization can be found in [this discussion](https://github.com/mishoo/UglifyJS2/issues/886).
100101

101102
FAQs
102103
----
@@ -135,7 +136,7 @@ take gzip into account. To prove it, here are the gzipped sizes for the librarie
135136

136137
### Is `optimize-js` intended for library authors?
137138

138-
Yes! If you are already shipping a bundled, minified version of your library, then there's no reason not to also
139+
Sure! If you are already shipping a bundled, minified version of your library, then there's no reason not to also
139140
apply `optimize-js` (assuming you benchmark it and it does indeed help!). However if your users ever apply an additional layer of minification (notably with Uglify), then the parenthesis-wrapping optimization will be undone.
140141

141142
Ideally, `optimize-js` should be run _after_ Uglify, since Uglify strips extra parentheses and also [negates IIFEs by default](https://github.com/mishoo/UglifyJS2/issues/640).
@@ -163,6 +164,23 @@ guesses), it can be more judicious in applying the paren hack.
163164

164165
### Does this really work for every JavaScript engine?
165166

166-
For JavaScriptCore (Safari), I'm not sure. For Chakra, it [actually does optimize](https://github.com/mishoo/UglifyJS2/issues/640#issuecomment-247792319) the Uglify-style `!function(){}` format, but it's
167-
the only one I'm aware of that does that. `optimize-js` also optimizes some patterns that currently no JavaScript engine
168-
does the IIFE optimization for (e.g. `function(){}();`).
167+
Based on my tests, this optimization seems to work best for V8 (Chrome), followed by Chakra (Edge), followed by SpiderMonkey (Firefox). For JavaScriptCore (Safari) it seems to be basically a wash, or possibly a little worse than without. However, I still think `optimize-js` can be useful, because (in my experience) Safari is rarely a performance problem. Instead, most of your performance problems are likely to come from under-powered Android devices, meaning you want V8 to run as fast as possible.
168+
169+
In the case of Chakra, [Uglify-style IIFEs are actually already optimized](https://github.com/mishoo/UglifyJS2/issues/640#issuecomment-247792319), but adding `optimize-js` doesn't hurt because a
170+
function preceded by `'('` still goes into the fast path.
171+
172+
Contributing
173+
-----
174+
175+
Build and run tests:
176+
177+
```bash
178+
npm install
179+
npm test
180+
```
181+
182+
Run the benchmarks:
183+
184+
```bash
185+
npm run benchmark # then open localhost:9090 in a browser
186+
```

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.