I have a JavaScript file and want to load it only to some specific ids to load in head.
The domain when user is logged in is www.domain.com?id=122
And the script url is www.domain.com/script.js
And I put the script with parameter in head of home page if user is logged in www.domain.com/script.js?id=122
And I get the id from the current url by split and some JavaScript stuff. Now the problem is what to add in the script file to make the script load only for some specific ids
Technically you can check the URL parameter, and create a script tag from code only if you are satisfied:
if(location.search === "?id=122") {
let s = document.createElement("script");
s.src = "script.js";
document.head.append(s);
}
However it's not something what could be used for security purposes for example.