# Script File loads in Editor although it is not linked via "Editor Script"

**URL:** <https://forum.pinegrow.com/t/script-file-loads-in-editor-although-it-is-not-linked-via-editor-script/7202>\
**Category:** Pinegrow WP\
**Tags:** bug\
**Created:** [November 15, 2022, 11:55am UTC](https://forum.pinegrow.com/t/script-file-loads-in-editor-although-it-is-not-linked-via-editor-script/7202 "2022-11-15T11:55:35Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![Wolfgang.Hartl](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.pinegrow.com/wolfgang.hartl/32/4621_2.png) [@Wolfgang.Hartl](https://forum.pinegrow.com/u/Wolfgang.Hartl)\
**Post date:** [November 15, 2022, 11:55am UTC](https://forum.pinegrow.com/t/script-file-loads-in-editor-although-it-is-not-linked-via-editor-script/7202/1 "2022-11-15T11:55:35Z")

</div>

Hey there,

I am facing a weird Issue, I want to create a simple image carousel using splide.js! In the block-editor I show the images as a scrollable list via “overflow: scroll”. I’ve added the splide.min.js as dependency using the “script” option at block-level. For some reason it also loads the script inside the block-editor!

Another Question I have regarding script files is: Is there any possibility to conditionally load the scripts, meaning only load them when the block is used on that page. I think I read somewhere that it is possible with one of the newest WP-Features, which would be pretty cool because now all assets get loaded on every single page, which can lead to a very bloated site in my opinion! 😉

 ![Bildschirmfoto 2022-11-15 um 14.40.04](https://canada1.discourse-cdn.com/flex036/uploads/pinegrow/original/2X/0/0ad6bba78eb1ad4893b16cda23916ae63fd1b0f9.png)

Thanks in Advance  
Cheers  
Wolfgang

---

<div class="post-metadata">

**Author:** ![matjaz](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.pinegrow.com/matjaz/32/5_2.png) [@matjaz](https://forum.pinegrow.com/u/matjaz)\
**Post date:** [November 15, 2022, 7:53pm UTC](https://forum.pinegrow.com/t/script-file-loads-in-editor-although-it-is-not-linked-via-editor-script/7202/3 "2022-11-15T19:53:30Z")

</div>

@Wolfgang.Hartl looking closer at WP code:

- the script is included on both front end and in the editor.
- the editor script is included only in the editor

See docs for [register\_block\_type() | Function | WordPress Developer Resources](https://developer.wordpress.org/reference/functions/register_block_type/)

The relevant parameters are

- `editor_script_handles` string Block type editor only script handles.
- `script_handles` string Block type front end and editor script handles.

So, the tooltip text in PG is wrong.

That said, there is also the `view_script_handles` parameter that includes the script only on the front end. I added the “View script” parameter to the Block action.

> [@Wolfgang.Hartl](#):
>
> Another Question I have regarding script files is: Is there any possibility to conditionally load the scripts, meaning only load them when the block is used on that page

AFIK, this is default behavior for both block styles and scripts. Only those of used blocks are included on the displayed page.

---

<div class="post-metadata">

**Author:** ![matjaz](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.pinegrow.com/matjaz/32/5_2.png) [@matjaz](https://forum.pinegrow.com/u/matjaz)\
**Post date:** [November 15, 2022, 8:48pm UTC](https://forum.pinegrow.com/t/script-file-loads-in-editor-although-it-is-not-linked-via-editor-script/7202/4 "2022-11-15T20:48:13Z")

</div>

Added to PG WP plugin 0.1.1 BETA, out in the next PG release.

---

<div class="post-metadata">

**Author:** ![Wolfgang.Hartl](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.pinegrow.com/wolfgang.hartl/32/4621_2.png) [@Wolfgang.Hartl](https://forum.pinegrow.com/u/Wolfgang.Hartl)\
**Post date:** [November 16, 2022, 7:56am UTC](https://forum.pinegrow.com/t/script-file-loads-in-editor-although-it-is-not-linked-via-editor-script/7202/5 "2022-11-16T07:56:05Z")

</div>

> [@matjaz](#):
>
> AFIK, this is default behavior for both block styles and scripts. Only those of used blocks are included on the displayed page.

Just double checked it and it seems that this doesn’t work for me. When I remove the script file from here it doesn’t get loaded on pages, where I don’t use that block. When the script file is linked here it get’s loaded on all pages! ☹

I’m using that block only on one page though.

 ![Bildschirmfoto 2022-11-16 um 08.55.04](https://canada1.discourse-cdn.com/flex036/uploads/pinegrow/original/2X/0/02de9b67eb03eba460a8a74ac8eda460ae939bd2.png)

EDIT: Just realized that the same seems to happen for the CSS-File!

---

<div class="post-metadata">

**Author:** ![Wolfgang.Hartl](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.pinegrow.com/wolfgang.hartl/32/4621_2.png) [@Wolfgang.Hartl](https://forum.pinegrow.com/u/Wolfgang.Hartl)\
**Post date:** [November 16, 2022, 7:56am UTC](https://forum.pinegrow.com/t/script-file-loads-in-editor-although-it-is-not-linked-via-editor-script/7202/6 "2022-11-16T07:56:32Z")

</div>

> [@matjaz](#):
>
> @Wolfgang.Hartl looking closer at WP code:
> 
> - the script is included on both front end and in the editor.
> - the editor script is included only in the editor
> 
> See docs for [register\_block\_type() | Function | WordPress Developer Resources](https://developer.wordpress.org/reference/functions/register_block_type/)
> 
> The relevant parameters are
> 
> - `editor_script_handles` string Block type editor only script handles.
> - `script_handles` string Block type front end and editor script handles.
> 
> So, the tooltip text in PG is wrong.
> 
> That said, there is also the `view_script_handles` parameter that includes the script only on the front end. I added the “View script” parameter to the Block action.

Great, thanks for the fix! 🙂

One more question. Is it also possible somehow to execute code whenever the block changes? Is there something like an onChange() method on GB-Blocks? Would be cool for several more complex blocks! 🙂

---

<div class="post-metadata">

**Author:** ![matjaz](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.pinegrow.com/matjaz/32/5_2.png) [@matjaz](https://forum.pinegrow.com/u/matjaz)\
**Post date:** [November 17, 2022, 3:37pm UTC](https://forum.pinegrow.com/t/script-file-loads-in-editor-although-it-is-not-linked-via-editor-script/7202/7 "2022-11-17T15:37:30Z")

</div>

> [@Wolfgang.Hartl](#):
>
> One more question. Is it also possible somehow to execute code whenever the block changes? Is there something like an onChange() method on GB-Blocks? Would be cool for several more complex blocks!

It’s probably possible by hooking in the WP Block editor with JS code. That would be beyond PG, though.

---

<div class="post-metadata">

**Author:** ![matjaz](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.pinegrow.com/matjaz/32/5_2.png) [@matjaz](https://forum.pinegrow.com/u/matjaz)\
**Post date:** [November 17, 2022, 3:39pm UTC](https://forum.pinegrow.com/t/script-file-loads-in-editor-although-it-is-not-linked-via-editor-script/7202/8 "2022-11-17T15:39:13Z")

</div>

> [@Wolfgang.Hartl](#):
>
> Just double checked it and it seems that this doesn’t work for me. When I remove the script file from here it doesn’t get loaded on pages, where I don’t use that block. When the script file is linked here it get’s loaded on all pages!

@Wolfgang.Hartl is this a theme or plugin? If it is a theme and the JS file is included on one of the source template files in HTML, it will get enqueued in the theme. In such cases add Don’t export action to that script tag.

---

<div class="post-metadata">

**Author:** ![Wolfgang.Hartl](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.pinegrow.com/wolfgang.hartl/32/4621_2.png) [@Wolfgang.Hartl](https://forum.pinegrow.com/u/Wolfgang.Hartl)\
**Post date:** [November 17, 2022, 3:55pm UTC](https://forum.pinegrow.com/t/script-file-loads-in-editor-although-it-is-not-linked-via-editor-script/7202/9 "2022-11-17T15:55:10Z")

</div>

> [@matjaz](#):
>
> @Wolfgang.Hartl is this a theme or plugin? If it is a theme and the JS file is included on one of the source template files in HTML, it will get enqueued in the theme. In such cases add Don’t export action to that script tag.

Thanks for your answer matjaz! 😉

I’ve tried all that but it still get loaded. The template is set to “do not export”, the script itself is also set to “do not enqueue”, so it shouldn’t get loaded in my opinion, right?

I’ve tested to unlink it from the block action, and when I remove it there it doesn’t get loaded on the frontend any longer. So it’s really only available if I use it on the block level itself.

I’m gonna double-check again if it get’s loaded on any other page when I’m back on the pc. But on the index.html (which is the only html-template that get’s exported on that theme) it is definitely not set!

---

<div class="post-metadata">

**Author:** ![Wolfgang.Hartl](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.pinegrow.com/wolfgang.hartl/32/4621_2.png) [@Wolfgang.Hartl](https://forum.pinegrow.com/u/Wolfgang.Hartl)\
**Post date:** [November 18, 2022, 7:32am UTC](https://forum.pinegrow.com/t/script-file-loads-in-editor-although-it-is-not-linked-via-editor-script/7202/10 "2022-11-18T07:32:54Z")

</div>

@matjaz I’ve now checked it again and the splide.min.js File is only used on 1 HTML-File. That specific file is set to “don’t export this page” and the script itself is set to “do not enqueue”.

So the only place where it could get enqueued is the block itself!

 ![Bildschirmfoto 2022-11-18 um 08.32.28](https://canada1.discourse-cdn.com/flex036/uploads/pinegrow/original/2X/d/d3bbc75f39fa9fb4501b0b3d5df7e6c1a9e53a37.png)

---

<div class="post-metadata">

**Author:** ![MichelyWeb](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.pinegrow.com/michelyweb/32/6652_2.png) [@MichelyWeb](https://forum.pinegrow.com/u/MichelyWeb)\
**Post date:** [September 23, 2023, 5:13pm UTC](https://forum.pinegrow.com/t/script-file-loads-in-editor-although-it-is-not-linked-via-editor-script/7202/11 "2023-09-23T17:13:47Z")

</div>

> [@Wolfgang.Hartl](#):
>
> So the only place where it could get enqueued is the block itself!

was this fixed in the meantime?

---

<div class="post-metadata">

**Author:** ![MichelyWeb](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.pinegrow.com/michelyweb/32/6652_2.png) [@MichelyWeb](https://forum.pinegrow.com/u/MichelyWeb)\
**Post date:** [September 23, 2023, 5:18pm UTC](https://forum.pinegrow.com/t/script-file-loads-in-editor-although-it-is-not-linked-via-editor-script/7202/12 "2023-09-23T17:18:00Z")

</div>

> [@matjaz](#):
>
> AFIK, this is default behavior for both block styles and scripts. Only those of used blocks are included on the displayed page.

I face the same problem as @Wolfgang.Hartl here. Script ans CSS of Blocks is loaded even if the block is not added to the page (Hybrid Block in my case).

---

<div class="post-metadata">

**Author:** ![matjaz](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.pinegrow.com/matjaz/32/5_2.png) [@matjaz](https://forum.pinegrow.com/u/matjaz)\
**Post date:** [September 25, 2023, 11:41am UTC](https://forum.pinegrow.com/t/script-file-loads-in-editor-although-it-is-not-linked-via-editor-script/7202/13 "2023-09-25T11:41:52Z")

</div>

@Wolfgang.Hartl and @MichelyWeb please send your project to [support@pinegrow.com](mailto:support@pinegrow.com) so that I can investigate. Thanks!

---

<div class="post-metadata">

**Author:** ![MichelyWeb](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.pinegrow.com/michelyweb/32/6652_2.png) [@MichelyWeb](https://forum.pinegrow.com/u/MichelyWeb)\
**Post date:** [September 25, 2023, 2:45pm UTC](https://forum.pinegrow.com/t/script-file-loads-in-editor-although-it-is-not-linked-via-editor-script/7202/14 "2023-09-25T14:45:57Z")

</div>

> [@matjaz](#):
>
> please send your project to [support@pinegrow.com](mailto:support@pinegrow.com) so that I can investigate. Thanks!

Done! Thanks in advance.

---

<div class="post-metadata">

**Author:** ![MichelyWeb](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.pinegrow.com/michelyweb/32/6652_2.png) [@MichelyWeb](https://forum.pinegrow.com/u/MichelyWeb)\
**Post date:** [September 25, 2023, 2:59pm UTC](https://forum.pinegrow.com/t/script-file-loads-in-editor-although-it-is-not-linked-via-editor-script/7202/15 "2023-09-25T14:59:42Z")

</div>

On a page without any blocks added to it: all my Hybrid Blocks css is loaded:

 ![CleanShot 2023-09-25 at 16.57.26@2x](https://canada1.discourse-cdn.com/flex036/uploads/pinegrow/original/2X/b/b0af0fdedc9cecd51353ae38876c9cc8db547954.png)

---

<div class="post-metadata">

**Author:** ![matjaz](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.pinegrow.com/matjaz/32/5_2.png) [@matjaz](https://forum.pinegrow.com/u/matjaz)\
**Post date:** [September 26, 2023, 12:10pm UTC](https://forum.pinegrow.com/t/script-file-loads-in-editor-although-it-is-not-linked-via-editor-script/7202/16 "2023-09-26T12:10:23Z")

</div>

@MichelyWeb @Wolfgang.Hartl, well, this was enlightening 🙂

By default, WordPress loads styles and scripts of all registered blocks on the front-end, regardless if blocks are used on the page or not. It appears the change happened in WP 5.8.

To load only assets of blocks that are used on the page, add the following code to `inc/custom.php`:

```auto
add_filter( 'should_load_separate_core_block_assets', '__return_true' );

```

Starting from Pinegrow Web Editor 7.8, WordPress plugin 1.0.15 and Theme Converter 2.2 (next updates) the WordPress builder can do this for you if you enable the **Load only styles and scripts of blocks that are displayed on the front-end** checkbox in project settings:

[![](https://docs.pinegrow.com/wp-content/uploads/load.block_.assets.at_.render.jpg)](https://docs.pinegrow.com/wp-content/uploads/load.block_.assets.at_.render.jpg)

I added the above to our docs on block styling and scripts:

> **[Custom Blocks Styling and Scripts | Pinegrow Web Editor](https://pinegrow.com/docs/wordpress/creating-custom-wordpress-blocks/styling-the-blocks/)**
>
> How to add custom styling to our blocks?

---

<div class="post-metadata">

**Author:** ![MichelyWeb](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.pinegrow.com/michelyweb/32/6652_2.png) [@MichelyWeb](https://forum.pinegrow.com/u/MichelyWeb)\
**Post date:** [September 26, 2023, 1:45pm UTC](https://forum.pinegrow.com/t/script-file-loads-in-editor-although-it-is-not-linked-via-editor-script/7202/17 "2023-09-26T13:45:09Z")

</div>

> [@matjaz](#):
>
> By default, WordPress loads styles and scripts of all registered blocks on the front-end, regardless if blocks are used on the page or not. It appears the change happened in WP 5.8.

Damn! That’s strange!

Thank you @matjaz for investigating and providing a solution.

---

<div class="post-metadata">

**Author:** ![matjaz](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.pinegrow.com/matjaz/32/5_2.png) [@matjaz](https://forum.pinegrow.com/u/matjaz)\
**Post date:** [September 28, 2023, 12:03pm UTC](https://forum.pinegrow.com/t/script-file-loads-in-editor-although-it-is-not-linked-via-editor-script/7202/18 "2023-09-28T12:03:18Z")

</div>

The above mentioned setting is now available in Pinegrow 7.72:

> **[Release Pinegrow Web Editor 7.72 · Pinegrow/PinegrowReleases](https://github.com/Pinegrow/PinegrowReleases/releases/tag/pg7.72)**
>
> An official repository for all Pinegrow releases. Contribute to Pinegrow/PinegrowReleases development by creating an account on GitHub.
