instantpage / instant.page

Make your site’s pages instant in 1 minute and improve your conversion rate by 1%
https://instant.page
MIT License
6.04k stars 205 forks source link

Optimize memory if !isSupported #9

Closed crazy4groovy closed 5 years ago

crazy4groovy commented 5 years ago

Hi, cool lib! I think you can save a bit of js memory around if (isSupported) { https://github.com/instantpage/instant.page/blob/master/instantpage.js#L11

You don't need to define any functions at all in this case, since they are never referenced. Maybe just an early exit from the module would be better? eg. if (!isSupported) return

dieulot commented 5 years ago

return isn’t supported outside of functions, the solution would be to wrap every function in an if, but that would make the code ugly so I won’t do it.

kurtextrem commented 5 years ago

Another solution would be using const xy = function xy() {} to define functions instead of function xy{}, which prevents hoisting of functions.