0

I am using AJAX to load pages, and am wondering what is the most efficient way to initialize JS that is stored in an external sheet on every page load. I have just made a bunch of functions and one "container" function that I call whenever load() is finished inserting content.

Basically:

function initContainer() {

  functionOne();
  functonTwo();
  functionThree();
  ...
  ...
  ...
} 

I have a quite complex site/app, and there is a lot of functions. It seems very inefficient and bad, but I am not having any problems per se. Am just wondering what I can do to make this better.

I am using smoothState.js for some of the page loads and it only has one onAfter hook, therefore I must have a function like initContainer() because I dont't really know which page is gonna get loaded and which functions I am going to use.

Thank you

Svedr
  • 589
  • 2
  • 6
  • 21
  • You can make use of async and defer attributes on your script tag: http://www.growingwiththeweb.com/2014/02/async-vs-defer-attributes.html But make sure you **understand** what they do before using them, or else you'll run into problems. Other than that, you'll have to explain more clearly what it is you want. Is it minimizing the file size? Minimizing the time it takes to run? – Daniel T. Feb 25 '17 at 03:20
  • My app is not experiencing any performance issues at all. What I am asking is if this is inefficient. My JS loads at the bottom of the page in a single file. There is no – Svedr Feb 25 '17 at 03:29
  • learn about [tag:wepack] + [tag:reactjs] + [tag-react-router] ,then , your life will change – Abdennour TOUMI Feb 25 '17 at 03:31
  • @Svedr Can you elaborate more on what you mean by inefficient? What are your concerns? – Daniel T. Feb 25 '17 at 03:35
  • If you're not having any performance problems, then what exactly is motivating your desire to change anything?? – Pointy Feb 25 '17 at 03:35
  • I love reactjs, but sadly the back-end for the app that I am currently working on is not based on an API and everything is rendered server-side with Java in .jsp pages. – Svedr Feb 25 '17 at 03:36

0 Answers0