3
I was thinking of something for calling Jquery plugins, I would call all plugins in a single page, but loading them only if they are used.
For example:
On page X I use Datatables, then:
if($(".dataTable") != undefined){ //se a página usar o dataTable
if($.dataTable == undefined){ //e se ele não foi carregado
//carregaria os arquivos necessários
$.getScript("dataTable.min.js", function(){
$(".dataTable").dataTable(); //e então incluiria a chamada
});
}
}
This would be done for all plugins used throughout the system. This way, only the plugins used on the page would be loaded, and would not need to be including the files and the so-called page by page.
My doubts are:
- That would be feasible?
- Is there any way to do something like this?
The language used is PHP.
It’s just that I’m actually using the following Dashboard: http://demo.kimlabs.com/gentelella/production/, it provides several interesting plugins, would like to leave the call of all of them available but this would be TOO heavy for loading, and loading them only on the pages on which they were used would be a job (besides being horrible for maintenance).
Loading while running Javascript would be too slow (unviable). There is not a good model to follow and as a web developer I believe that this is some of the dilemmas of HTML development. Put in question your file structure and page calls, language and etc. So I can help with some ideas I have on the subject.
– KaduAmaral
I left more information at the end of the question, thanks in advance.
– Mukotoshi
@Mukotoshi I think it would be nice if you change the title to "Javascript library loading on demand".. just a suggestion :D
– Brunno