A question about Loader baseURL
hax.sfo at gmail.com
Mon Aug 27 07:32:22 PDT 2012
On Mon, Aug 27, 2012 at 10:14 PM, Sam Tobin-Hochstadt <samth at ccs.neu.edu> wrote:
>> So in /lib/b.js , System.baseURL will return a diff result
>> "http://example.com/lib/b.js" ?
> This depends on how you're loading "b.js".
Could explain more about that? I suppose b.js is loaded by system loader.
>> I want:
>> myLoader.load('test.js') // load /a/test.js
>> myLoader.load('test.js') // load /b/test.js
>> But myFetch get the identical args: ('test.js', myLoader.baseURL)
>> HOW can myFetch know the correct URL? (Holding System.baseURL seems
>> useless in this case.)
> `load` is a method, which can be called anywhere. Having it depend on
> a dynamically-scoped bit of information such as the url of the file
> that the method is called in, would make using loaders much harder to
I don't think so. Loader is a very special util, and I believe most
coders expect the behavior I described, and that also match the
behavior of System loader (what I confirmed in early post), or require
> This is just like current browser behavior when you insert a `<script
> src="test.js">` tag -- "test.js" is looked up relative to the URL of
> the *page*, not relative to the URL of the js file that does the dom
That's WHY we need loader in JS, not script tag in HTML.
And current ES3/5 loaders are all trying to solve the base URL by
tricks (such as check script.readystate and find which script is
running and get the right baseURL)
More information about the es-discuss