Skip to content

Improve code for better minification#2

Open
mgreter wants to merge 1 commit intotysonmatanich:masterfrom
mgreter:minification
Open

Improve code for better minification#2
mgreter wants to merge 1 commit intotysonmatanich:masterfrom
mgreter:minification

Conversation

@mgreter
Copy link

@mgreter mgreter commented Apr 24, 2017

Thanks for the function, going to need it for responsive images.
Since I need to include this in the html head, I thought after
reviewing it, that it could be easily compressed even more.

I slighly adjusted and simplified the implementation a bit
to improve minification. Mainly by getting some base objects
like screen into variables, so the minfier only sees them once.

I also changed the checks a little, which should IMO be safe. You
explicitly check for !== undefiend, but I guess only positive numbers
really make sense in the later calculation. Therefore a simple || 1 seems
even a bit safer, as it protects from a possible division by zero.

Google closure compiler minfies the new code to 151 bytes, while
the current implementation is at 281 bytes 😃 I double checked that
I did not include any errors and tried to make sure the logic is sane.
Ie. it is now guaranteed to never return zero, which seems desirable!

Thanks and kind regards!

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.

1 participant