Disable option for JS scripts

Similarly to CSS files, it would be convenient if a “disable” option was added for external or internal JS links/files without interfering with the “show only on these pages” option.

For example, say I have a js file that is set to show on 3 specific pages, if I wanted, I could just hit the disable option and make the file not show on any pages. But if I re-enabled it, it would show on the 3 specific pages as configured before.

I assume implementation of this would be fairly simple since similar code exists for CSS files?

1 Like

We appreciate the suggestion! The CSS disable option is a shortcut to disabling all CSS blocks in the file. For JS this would mean wrapping the contents of the file within a /**/ comment.

If the app just blindly wraps the code in a comment, this might result in broken JS depending on what other comments exist in the code already. To make it work reliably we will have to parse the JS code and handle all manner of corner cases.

Given that users can easily comment the JS code themselves, I think it’s not worth pursuing this feature.

Thanks for the response. My primary use case for this would’ve been externally linked scripts rather than js files that can be commented to disable it.

The issue is when setting it to serve on specific pages, if you want to disable it temporarily, the only way is to uncheck all those specific pages then re-check them again after to enable it again.

This can be a hassle if you have many pages in your design, remembering what pages to enable the script on and what pages not to.

Also, although like I said my primary use case would be for externally linked scripts, an idea to achieve disabling js files without there being issues from /**/ would be to just add // at the start of every line in the file. This shouldn’t cause any issues, I don’t believe there would be corner cases for this, VSCode does the same thing with bulk commenting to avoid many corner cases.

Thanks for the info! You are right, for linked JS files another approach will be needed. We will look into adding disabling in our next updates.

1 Like

@martin

In the visibility dropdown there could be a choice visible on no page which means the javascript file will be exported but in the html no script tag. When I’m working with modules and dynamically import the module files, I have to create a dummy.html and set the visible on those module files to only the dummy.html. The dummy.html I hide in the export.
Even better would be if you can make a folder in the javascript section and set that folder to visible on no page so all files in that folder will be exported but no script tags on any of the html files

1 Like

Thank you for the suggestion! We will look into adding such a setting.

1 Like

+1 on the folders for all sections. It’s so much easier to make a folder and hide it than to have to go through every file and do it. Drag and drop multiple files and done! Hope to see that for all sections at some point.

Would also love to see a “Hide” selection on the dialog for the files so that you don’t have to do the ‘all except these pages’ setup. Might be some reason it’s like that so if so just let me know as I haven’t figured it out yet lol. It’s a bit confusing I’m sure to others too, that when you want to hide something completely you have to do ‘all except’ and check them all. But as I said, might be a reason for that so if so I’d be curious to know what it is. :slight_smile:

Of course, if you do the folders thing then it’s perfect and makes perfect sense so … FOLDERS! LOL