What happens? When having the file in a library in SharePoint Online, anything removes the two dots (“..”). The result: the script could not be found, the page does not behave as expected any more. The dots are not removed directly after I store the file in the library, it happens one or two days later.
So, I have to load the script file in any other way, but I still want to be able to use site or web relative paths. To solve this problem, the functions SP.SOD.registerSod and SP.SOD.executeFunc will do the trick. Here is a simple example for a script, where I additionally use the function SP.SOD.registerSodDep:
This example uses the webServerRelativeUrl member of _spPageContextInfo, where SharePoint stores the relative URL of the current web site. When the script is stored in the root site of the site collection, the member siteServerRelativeUrl could be used instead.