Question

This title is giving me a warning about the question being subjective but I hope that's not the case.

Here's my situation: I have several functions(some are used on many pages, some only on one page) and I put them all into one .js file to save on load time. However, some pages run functions onload. For this to work, I need to have the functions file declared prior to the call. However, some of the functions require the page to be generated before it can grab the information it needs, so the file declare has to be at the end of the page. So right now, I've made two file declarations on the same page, for the same file. Looking in the console, this obviously causes problems as the first file can't get the information it needs, and throws an error.

So my question: Would it be best to break the functions in to two files (one pre-load one post?) or should the problem ones (which are functions unique to the page anyway) be hard coded at the top?

Was it helpful?

Solution

The best solution would be to break it into two files. That way you can reuse the code in more pages since the pre-load scripts work as they're supposed to, and the post-load scripts get the information they require. It would make the rest of you coding much easier.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top