+22
-4
lines changedFilter options
+22
-4
lines changed Original file line number Diff line number Diff line change
@@ -97,6 +97,7 @@ Luckily, because the `'('` optimization for IIFEs is so well-established, we can
97
97
parsing the entire JavaScript file in advance (a luxury the browser can't afford) and inserting parentheses in the cases where we _know_
98
98
the function will be immediately executed (or where we have a good hunch). That's what `optimize-js` does.
99
99
100
+
More details on the IIFE optimization can be found in [this discussion](https://github.com/mishoo/UglifyJS2/issues/886).
100
101
101
102
FAQs
102
103
----
@@ -135,7 +136,7 @@ take gzip into account. To prove it, here are the gzipped sizes for the librarie
135
136
136
137
### Is `optimize-js` intended for library authors?
137
138
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
139
140
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.
140
141
141
142
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.
163
164
164
165
### Does this really work for every JavaScript engine?
165
166
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
+
```
You can’t perform that action at this time.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4