My goal is to load a PlaceOne.js file only when needed.
My current code in the index.js is
if (placeID === "placeone") {
return new PlaceOne(id, PlaceInitialData);
}
And the PlaceOne.js is simply implemented into my index.html at the end of the body. Everything works fine.
But as soon as I remove the PlaceOne.js file from the Index I get the Errormessage that PlaceOne is not defined. So now I want to load it when my placeID is "placeone" After some research I found the solution of getScript. So I tried the following:
if (placeID === "placeone") {
$.getScript( "js/PlaceOne.js" )
return new PlaceOne(id, PlaceInitialData);
}
But I still get the Errormessage that PlaceOne is not defined I also would like to check if the file is already loaded or currently loading to avoid a multiple loading of the file.