Title: Don&#8217;t combine JavaScript type=module by default?
Last modified: May 17, 2022

---

# Don’t combine JavaScript type=module by default?

 *  Resolved [Remco Tolsma](https://wordpress.org/support/users/remcotolsma/)
 * (@remcotolsma)
 * [4 years ago](https://wordpress.org/support/topic/dont-combine-javascript-by-default/)
 * On a website we are currently getting the following error:
 * `Uncaught SyntaxError: Cannot use import statement outside a module (at siteground-
   optimizer-combined-js-4c066a5266b58bf7cc9930ae49d96fe4.js:122:508)`
 * This is because a plugin enqueues a module script and changes the script tag 
   via the `script_loader_tag` filter to `<script type="module" src="..."></script
   >`.
 * [https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script#attr-type](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script#attr-type)
 * We were wondering if it might be wise for the SiteGround Optimizer to exclude
   scripts with `type="module"` from combining JavaScript by default?
 * Or are there situations where `<script type="module" src="..."></script>` can
   be successfully combined? (I’m not a JavaScript expert).
    -  This topic was modified 4 years ago by [Remco Tolsma](https://wordpress.org/support/users/remcotolsma/).
    -  This topic was modified 4 years ago by [Remco Tolsma](https://wordpress.org/support/users/remcotolsma/).

Viewing 7 replies - 1 through 7 (of 7 total)

 *  Plugin Support [Georgi Ganchev](https://wordpress.org/support/users/georgiganchev/)
 * (@georgiganchev)
 * [4 years ago](https://wordpress.org/support/topic/dont-combine-javascript-by-default/#post-15655366)
 * Hello [@remcotolsma](https://wordpress.org/support/users/remcotolsma/),
 * We have informed our developers about the issue and they will take the time to
   investigate this and consider if we can modify the plugin to exclude such scripts.
 * If we require further details from your end we will update this thread.
 * Best regards,
    Georgi Ganchev
 *  Plugin Author [Elena Chavdarova](https://wordpress.org/support/users/elenachavdarova/)
 * (@elenachavdarova)
 * [3 years, 7 months ago](https://wordpress.org/support/topic/dont-combine-javascript-by-default/#post-16092310)
 * Hi [@remcotolsma](https://wordpress.org/support/users/remcotolsma/),
 * We have included a filter to the plugin which you can use to exclude all inline
   scripts of type module from combination.
 * The filter you can use is:
 * `add_filter( 'sgo_javascript_combine_exclude_all_inline_modules', '__return_true');`
 * Additionally there is a filter which will exclude all inline scripts no matter
   of their type as well:
 * `add_filter( 'sgo_javascript_combine_exclude_all_inline', '__return_true' );`
 * I hope this will be of help!
 * Best Regards,
    Elena
 *  Thread Starter [Remco Tolsma](https://wordpress.org/support/users/remcotolsma/)
 * (@remcotolsma)
 * [3 years, 7 months ago](https://wordpress.org/support/topic/dont-combine-javascript-by-default/#post-16095982)
 * Thanks, but without answers to our questions I don’t know if a filter is the 
   best solution.
 * > We were wondering if it might be wise for the SiteGround Optimizer to exclude
   > scripts with `type="module"` from combining JavaScript by default?
   > Or are there situations where `<script type="module" src="..."></script>` can
   > be successfully combined? (I’m not a JavaScript expert).
 * if `<script type="module" src="..."></script>` scripts should not be combined
   at all then you shouldn’t introduce a filter, but exclude it by default.
 *  Plugin Author [Hristo Pandjarov](https://wordpress.org/support/users/hristo-sg/)
 * (@hristo-sg)
 * SiteGround Representative
 * [3 years, 7 months ago](https://wordpress.org/support/topic/dont-combine-javascript-by-default/#post-16096076)
 * At this point we will not be excluding such scripts by default since that brings
   more risk of introducing bugs to users than using the filter when actually using
   it. Furthermore, each check increases the time necessary to process the request.
 *  Thread Starter [Remco Tolsma](https://wordpress.org/support/users/remcotolsma/)
 * (@remcotolsma)
 * [3 years, 7 months ago](https://wordpress.org/support/topic/dont-combine-javascript-by-default/#post-16096384)
 * Hmm, without the answers to my questions I don’t know if that’s true. After all
   combining `<script type="module" src="..."></script>` by default caused an issue,
   that’s why this topic exists.
 *  Plugin Author [Hristo Pandjarov](https://wordpress.org/support/users/hristo-sg/)
 * (@hristo-sg)
 * SiteGround Representative
 * [3 years, 7 months ago](https://wordpress.org/support/topic/dont-combine-javascript-by-default/#post-16098974)
 * Yes, enabling combination does that. Exceptions are handled by default rules,
   interface, filter or both. This current case will be covered by a filter. I am
   sorry if that’s not your preferred way to handle this.
 *  Thread Starter [Remco Tolsma](https://wordpress.org/support/users/remcotolsma/)
 * (@remcotolsma)
 * [3 years, 7 months ago](https://wordpress.org/support/topic/dont-combine-javascript-by-default/#post-16100024)
 * Haha, it’s not about my preferred way to handle this. I think it should be about
   how you can best deal the combining `<script type="module" src="..."></script
   >` elements / scripts by default. That remains a bit in the middle, but maybe
   it can’t get any better.

Viewing 7 replies - 1 through 7 (of 7 total)

The topic ‘Don’t combine JavaScript type=module by default?’ is closed to new replies.

 * ![](https://ps.w.org/sg-cachepress/assets/icon-256x256.gif?rev=2971889)
 * [Speed Optimizer - The All-In-One Performance-Boosting Plugin](https://wordpress.org/plugins/sg-cachepress/)
 * [Support Threads](https://wordpress.org/support/plugin/sg-cachepress/)
 * [Active Topics](https://wordpress.org/support/plugin/sg-cachepress/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/sg-cachepress/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/sg-cachepress/reviews/)

## Tags

 * [Import](https://wordpress.org/support/topic-tag/import/)
 * [javascript](https://wordpress.org/support/topic-tag/javascript/)
 * [module](https://wordpress.org/support/topic-tag/module/)
 * [syntaxerror](https://wordpress.org/support/topic-tag/syntaxerror/)

 * 7 replies
 * 4 participants
 * Last reply from: [Remco Tolsma](https://wordpress.org/support/users/remcotolsma/)
 * Last activity: [3 years, 7 months ago](https://wordpress.org/support/topic/dont-combine-javascript-by-default/#post-16100024)
 * Status: resolved