Follow treslines by email clicking Here!

Thursday, October 13, 2016

Today i'm gonna show you, how to import / add javascript dependencies dynamically to your html files. I'm playing with object orientation in javascript and in this context, I've created a class that does exactly that and I'd like to share with you.

'use strict'
/**
* Use this class to import all dependencies dynamically into your html.
* This class imports the dependencies only if not exits already.
*

The idea behind this post not to "lazy load" but further more to remove imports from the html and maintain and controll it in a single place (in the place where you need it) and to avoid duplicity besides the idead to show some OOP concepts using javascript.

In the practise, we didn't see any problem or noticed any issue with it. Your suggestion with with the "appentTo" is really a better choice. Very well observed. Thanks a lot for that. :)