Support Forums

Links to .js files

hello there, so i have a problem, i was adviced to split my javascript code in two files one for each page of my website.
so i have index.html and page2.html, i already split it and i have it like this…
script defer src=“page.js”></script
script defer src=“page1.js”></script
script defer src=“page.js”></script
script defer src=“page2.js”></script
but it doesnt work unless you reload the webiste on page 2, and this happens because the link to page2.js its not on the index.html, i can use inline but i havent tried, is there a solution for this case???

Hi @lenguaestudiocreativ,

The questions you’re asking are more appropriate for a coding forum like StackOverflow. There’s no problem with these questions but they’re not really related to Netlify and might take longer to get them answered.

With that being said, you should really show examples of what you’re trying or any examples that can show what you’ve already done. Without that, it’s just guesswork and harder to find the solution.

Now to answer your question, there are multiple ways to solve this:

  1. If each page loads individually like a typical static website, you need to add 2 different scripts on the pages individually.

  2. If there’s some kind of a navigation handler in the pages, you’d have to use one script file and check what page you’re on within that script.

hello @hrishikesh, well thanks anyway for your attention and support, so was thinking, maybe this issue its more related to the syntax of the code and sure it was, i change it to jquery and i think its working its not trhowing me the same DOM erros as before, ill try now the cache tip you told me before, ill let you know if i have questions regarding that later on, hope its ok…thanks