I am working on a site that calls various different pages and forms through ajax
. To save page loading times I'm trying to only load the .js files that I need for each page or form, but during development this causes several issues and errors, like events or elements having to be referenced through $(document)
. Also, Jquery now throws a deprecation warning for loading inline js through ajax.
I know I can call external scripts through jquery's .getScript()
function, and will be able to resolve all errors, but I'm wondering if it wouldn't just be a whole lot easier to include all the required script files in the main header (or footer).
What approach is more efficient in terms of work flow vs user experience? Load all the site js initially, or load scripts dynamically as needed? (In this case, total size of extraneous js files is approx 50kb)