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

Wrap JavaScript in an IIFE to prevent conflicts #60

Closed crgeary closed 4 years ago

crgeary commented 4 years ago

Added an IIFE around the existing code to scope variables to this library. The minified version, for example, has a constant called c which conflicts with another library on our site, also with a constant called c as neither are scoped.

(function () {
  // old code here
})();
dieulot commented 4 years ago

Hi, I won’t be accepting this.

It’s not recommended to bundle instant.page with the rest of your JS. Loading instant.page is low priority and is thus best served with a defer attribute. It’s also ES6 syntax and must be served as a module, which the rest of most sites’ scripts usually aren’t, so that older browsers don’t throw an error.

If one bundles it though, the usual way to do this is by loading it as a module nowadays, not by just concatenating scripts.

Thanks anyway.

crgeary commented 4 years ago

Hi,

Thanks for the response. My mistake, I didn't realise this was how type="module" worked.

Thanks for the information.

nikitasol commented 3 years ago

@dieulot Hi Alexandre! Could you recommend the best solution to this when using instant.page plugin for wordpress? At the moment the bundled version is not scoped and creates variable conflicts.