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

Minifier notes #32

Open
wcoder opened this issue Nov 21, 2021 · 0 comments
Open

Minifier notes #32

wcoder opened this issue Nov 21, 2021 · 0 comments

Comments

@wcoder
Copy link
Owner

wcoder commented Nov 21, 2021

Common strings

  • https://
  • remove www.
  • Not supported

Common DOM API

  • 188L,212L - getAttribute - use local func

Optional

  • navigator - 6
from: w.navigator w.navigator w.navigator w.navigator w.navigator w.navigator
to:   var a='navigator';w[a] w[a] w[a] w[a] w[a] w[a]
  • querySelectorAll - 3
from: d.querySelectorAll d.querySelectorAll d.querySelectorAll
to:   var a='querySelectorAll';d[a] d[a] d[a]

switch -> if

var a = 1;
var x;
var f = function (z) { return z+z; };

// Current:
switch(a){case 1:x=1;break;case 2:x=2;break;case 3:x=3;case 4:x=4;default:x=-1;}
switch(a){case 1:x=1;break;case 2:x=f(2);break;case 3:var b=1;x=f(a+b);if(x > 1)alert('win');case 4:x=4;default:x=-1;}

// Proposal 1:
if(a==1){x=1}else if(a==2){x=2}else if(a==3){x=3}else if(a==4){x=4}else{x=-1}
if(a==1){x=1}else if(a==2){x=f(2)}else if(a==3){var b=1;x=f(a+b);if(x > 1)alert('win')}else if(a==4){x=4;}else{x=-1}

// Proposal 2:
x=a==1?1:a==2?2:a==3?3:a==4?4:-1;
x=a==1?1:a==2?f(2):a==3?function(){var b=1;var c=f(a+b);if(c > 1)alert('win');return c}():a==4?4:-1;

Proposal 1 can be compressed automatically to 2 by uglify.

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

No branches or pull requests

1 participant