Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

optimize bundle size #66

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

AndyOGo
Copy link

@AndyOGo AndyOGo commented Feb 19, 2019

Really great tool.

I'm just keen if the bundle size could be reduzed by:

  • generating binary operator functions
  • caching access to global APIs
  • auto fix eslint errors
  • make internal usage of public API minifier friendly

Before:
https://bundlephobia.com/[email protected]

4.7kB Minified
1.6kB Minified + Gzipped

Now:

@AndyOGo
Copy link
Author

AndyOGo commented Feb 19, 2019

Tests still pass:

npm run test

> [email protected] test /Users/andy/work/js/json-logic-js
> gulp test

[21:33:26] Using gulpfile ~/work/js/json-logic-js/gulpfile.js
[21:33:26] Starting 'test'...
Using cached applies() tests
Using cached rule_like() tests
Including 39 rule_like() tests
Including 275 applies() tests

Summary:
┌────────────────────────────────────────────┬────────┬────────┬───────┬─────────┐
│ File                                       │ Failed │ Passed │ Total │ Runtime │
├────────────────────────────────────────────┼────────┼────────┼───────┼─────────┤
│ /Users/andy/work/js/json-logic-js/logic.js │ 0      │ 345    │ 345   │ 114     │
└────────────────────────────────────────────┴────────┴────────┴───────┴─────────┘


[21:33:27] Finished 'test' after 1.33 s

@AndyOGo AndyOGo changed the title feat: generate binary operations optimize bundle size Feb 19, 2019
* @return {Function} Operator function as specified by param
*/
function generateBinaryOperation(operations, operator) {
operations[operator] = new Function("a", "b", "return a" + operator + "b;");
Copy link

@computnik computnik Jul 16, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this equivalent of eval the code. I do understand the difference between eval & new Function (closure in new Function), but the concern that many users like me would have for avoiding eval & new Function would be around Content Security Policy
Read https://developer.chrome.com/extensions/contentSecurityPolicy#JSEval for more info

Copy link
Author

@AndyOGo AndyOGo Jul 16, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your feedback @computnik
Well, eval has access to current scope and local variables, in contrast to the new Function constructor - which has not!
This difference is very often miss-understood and has plenty of discussions on the web already.

Regarding CSP, your are right, it could make problems, especially in chrome.

https://stackoverflow.com/questions/4599857/are-eval-and-new-function-the-same-thing

Copy link
Author

@AndyOGo AndyOGo Jul 16, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Anyway meanwhile we have forked and completely rewrote this project and I added JSON-Schemas for all operators.
https://github.com/axa-ch/json-logic-js

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants