Forum Moderators: open

Message Too Old, No Replies

Can I have an empty JS file?

I need to change js file I no longer need so it will not do anything

         

lzr0

10:14 am on Jul 25, 2024 (gmt 0)

10+ Year Member



Hi, I have a certain js file on all my pages, which I no longer want to use. Instead of editing all my html pages by deleting the line calling for this file, can I just delete all content in this js file? Would it not cause any browsers issues/page delays? Otherwise, how can I update my js file so it would remain in html pages but not do anything?

not2easy

2:06 pm on Jul 25, 2024 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



You could change out the .js file content to lazy load a 1px clear image at the point where the .js would load. It could do that without major interruption. Loading an 'empty' file would be likely to cause errors.

Personally I would use find/replace in a text editor across all the pages and remove the .js link. ;)

lucy24

3:55 pm on Jul 25, 2024 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



It depends on what the html says. If every page just has something like
<script src = "outsidescripts.js"></script>
and then any further javascript activity takes place in that external file, it should make no difference if the js file is empty or even entirely absent. But if the html page itself calls on a function that lives in the js file--for example, a form that is mainly in the html but uses js content from elsewhere, or something that is supposed to be done "onload"--then you really ought to clean it up.

In any case: Unless there is something very unusual in your scripts, there shouldn’t be meaningful errors. That is, there might be an error in the innards of the browser--the kind that would be flagged by Developer Tools--but nothing that would be visible to the human user. The scripts simply wouldn’t execute.

not2easy

4:21 pm on Jul 25, 2024 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



Right, lucy24, the possibility of 'onload' scripts is what I was considering, about the causing errors part. Check the .js file to know which would be better.

lzr0

4:52 pm on Jul 25, 2024 (gmt 0)

10+ Year Member



@not2easy
You could change out the .js file content to lazy load a 1px clear image at the point where the .js would load...

Thank you. But would not I need to add a placeholder on the page for that image, which would mean editing all pages?

@lucy24
It depends on what the html says. If every page just has something like
<script src = "outsidescripts.js"></script>
and then any further javascript activity takes place in that external file, it should make no difference if the js file is empty or even entirely absent.


Yes, that's exactly what I have. Leaving the file blank would be the easiest thing for me. Thank you!

lucy24

8:10 pm on Jul 25, 2024 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



would not I need to add a placeholder on the page for that image
No, because the image is directly called by the js, not the on-page html. Of course you'll have to create that one-pixel transparent gif and put it somewhere, such as your top-level /images/ directory, but even if you forget, nothing catastrophic will happen.

html is intended to be forgiving, meaning that even if a browser meets something that makes no sense, it should carry on and do everything else on the page. Not like your average programming language, where if it encounters the tiniest of misplaced commas, it will stop dead in its tracks.

lzr0

3:37 am on Jul 26, 2024 (gmt 0)

10+ Year Member



@lucy24

OK, thank you, I see, but if as you said empty or missing js is not a problem, this will be the easiest workaround for me.