In requireJS, there is an attribute called baseURL. By setting baseURL, we can write the path of the file to be loaded relative to the project instead of relative to the current page.
For example: Suppose our project directory is /myproject/, there are two pages in it, one is /myproject/one.html, the other is /myproject/html/other.html, they both need to load /myproject/js /some.js. If we set the baseURL to /myproject/, then when we load the js, both pages can use the path relative to the project./js/some instead of using different relative paths because the paths of the pages are different. .
But if we don’t use requireJS, can we implement functions similar to baseURL?
base tag
In fact, there is a base tag in HTML that can produce similar functions. For example:
base tag can add a default path or default opening method to the page link.
The following is an example of setting the default opening method:
Chrome loads normally.
Firefox is not loading properly.
Why?
We didn’t find a good explanation for this. Our analysis is that the browser has optimized resource loading, so when the dynamically inserted base tag does not take effect, it is loaded in advance. The result is an error, and then the base tag takes effect. The correct resources are loaded again.
How to avoid it? If you don’t dynamically write the base tag, there will be no problem. If you need to write the base tag dynamically, then all external resources referenced by the page need to be dynamically loaded through Javascript.