Title: Can&#8217;t exclude javascript from being combined
Last modified: February 13, 2025

---

# Can’t exclude javascript from being combined

 *  Resolved [incoog](https://wordpress.org/support/users/incoog/)
 * (@incoog)
 * [1 year, 3 months ago](https://wordpress.org/support/topic/cant-exclude-javascript-from-being-combined/)
 * Hi!
 * I’m experiencing an issue with SiteGround Optimizer where it prevents an external
   JavaScript file from loading properly. The script in question is Klarna’s Web
   SDK, which is required for their On-Site Messaging to function.
 * **Issue Summary:**
    - When **“Combine JavaScript Files”** is enabled, the following script does **
      not load at all**:
      `<script async data-environment="production" src="https://
      js.klarna.com/web-sdk/v1/klarna.js" data-client-id="[REDACTED]"> </script>`
    - I have tried excluding `https://js.klarna.com/web-sdk/v1/klarna.js` from SiteGround
      Optimizer’s **“Exclude from JavaScript Combination”** setting, but the script
      is still not loading.
    - The script is also not included in the combined JavaScript file, meaning it
      is being completely removed rather than merged.
    - As a result, Klarna’s On-Site Messaging does not work on my site.
 * **What I Have Tried:**
    1. **Manually excluding Klarna’s script** from SiteGround Optimizer settings:
    2.  - Added `https://js.klarna.com/web-sdk/v1/klarna.js` under **“****Exclude from
          JavaScript Combination**“ → Does not work.
        - Added `https://js.klarna.com/web-sdk/v1/klarna.js` under **“****Exclude from
          JavaScript Minification**“ → Does not work.
    3. **Using SiteGround’s recommended PHP filter**
       `sgo_js_minify_exclude` → **This
       also does not work**—the script is still missing or not loading or combined 
       when JavaScript combination is enabled.
    4. Ensuring `wp_enqueue_script()` loads Klarna correctly and modifying `script_loader_tag`
       → Still does not work.
 * **Expected Outcome:**
 * I need Klarna’s script to **always load separately**, without being blocked, 
   removed, or optimized by SiteGround Optimizer. Since the recommended exclusion
   methods have not worked, **can you confirm how to properly exclude an external
   script like this?**
 * Thank you for your help!
 * This is my code:
 *     ```wp-block-code
       function enqueue_klarna_onsitemessaging_js() {    wp_enqueue_script(        'klarna-sdk',        'https://js.klarna.com/web-sdk/v1/klarna.js',        array(),        null,        false    );}add_action('wp_enqueue_scripts', 'enqueue_klarna_onsitemessaging_js');    function add_klarna_onsitemessaging_js_tag($tag, $handle) {        if ('klarna-sdk' === $handle) {            return '<script async data-handle="klarna_onsitemessaging" data-environment="production" data-client-id="[REDACTED]"></script>';        }        return $tag;    }add_filter('script_loader_tag', 'add_klarna_onsitemessaging_js_tag', 10, 2);add_filter( 'sgo_js_minify_exclude', 'js_minify_exclude' );function js_minify_exclude( $exclude_list ) {    $exclude_list[] = 'klara_onsitemessaging';    $exclude_list[] = 'klarna-sdk';    return $exclude_list;}
       ```
   
 * Best regards,
   Robin Alfredsson
 * The page I need help with: _[[log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Fcant-exclude-javascript-from-being-combined%2F%3Foutput_format%3Dmd&locale=en_US)
   to see the link]_

Viewing 1 replies (of 1 total)

 *  Plugin Support [Svetoslav Vasev](https://wordpress.org/support/users/svetoslavvasev/)
 * (@svetoslavvasev)
 * [1 year, 3 months ago](https://wordpress.org/support/topic/cant-exclude-javascript-from-being-combined/#post-18304171)
 * Hello [@incoog](https://wordpress.org/support/users/incoog/) ,
 * You can try excluding the external JS script from being combined by using the
   following filter:
   `add_filter( 'sgo_javascript_combine_excluded_external_paths','
   js_combine_exclude_external_script' );**function** **js_combine_exclude_external_script**(
   $exclude_list ) {$exclude_list[] = 'script-host.com';$exclude_list[] = 'script-
   host-2.com';**return** $exclude_list;}In your case, the filter should look like
   this:add_filter( 'sgo_javascript_combine_excluded_external_paths', 'js_combine_exclude_external_script');**
   function** **js_combine_exclude_external_script**( $exclude_list ) {$exclude_list[]
   = 'js.klarna.com';**return** $exclude_list;}In case this solution doesn’t yield
   the expected result, please submit a support inquiry via your SiteGround account
   and we’ll gladly review the matter further.
 * Best Regards,
 * Svetoslav Vasev

Viewing 1 replies (of 1 total)

The topic ‘Can’t exclude javascript from being combined’ 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/)

 * 1 reply
 * 2 participants
 * Last reply from: [Svetoslav Vasev](https://wordpress.org/support/users/svetoslavvasev/)
 * Last activity: [1 year, 3 months ago](https://wordpress.org/support/topic/cant-exclude-javascript-from-being-combined/#post-18304171)
 * Status: resolved