Re: [whatwg] <script> features

On Sun, 25 Mar 2012, Jonas Sicking wrote:
> On Fri, Mar 23, 2012 at 9:41 PM, Ian Hickson <ian@hixie.ch> wrote:
> > On Fri, 23 Mar 2012, Jonas Sicking wrote:
> >>
> >> The whole point of this feature is to enable the js-code inside a 
> >> loaded script to use the .currentScript property in order to find the 
> >> <script> element in the DOM which loaded it.
> >
> > Ah, ok. What's the use case for that?
> 
> One use case is to be able to pass parameters to a script library by 
> sticking the information in the markup. data-* attributes would work 
> great for this. I seem to recall jQuery doing something like this, but 
> can't find information about that right now.
> 
> In the case of ReSpec it uses it to get its own url and then use that as 
> a base url to load dependent scripts as needed.

On Sun, 25 Mar 2012, Aryeh Gregor wrote:
> 
> testharness.js also does that, I think -- it loads a CSS file from the 
> same directory as itself.  IIRC, it does so by looking for the first 
> <script> whose src ends in "testharness.js".  It would be more reliable 
> if it could record the actual URL it's being loaded from.
> 
> (For this use-case it would be enough for the script to get its own URL.  
> In fact, this might be slightly more reliable, because there's nothing 
> to stop an earlier part of the script from inadvertently changing the 
> <script> element's src.  That wouldn't satisfy the first use-case Jonas 
> mentioned, though.)

Cool, thanks for the info.

I've added the feature to the spec.

-- 
Ian Hickson               U+1047E                )\._.,--....,'``.    fL
http://ln.hixie.ch/       U+263A                /,   _.. \   _\  ;`._ ,.
Things that are impossible just take longer.   `._.-(,_..'--(,_..'`-.;.'

Received on Thursday, 29 November 2012 01:10:05 UTC