Improve code for better minification#2
Open
mgreter wants to merge 1 commit intotysonmatanich:masterfrom
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
screeninto 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 numbersreally make sense in the later calculation. Therefore a simple
|| 1seemseven 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!