How does html5-script-attribute "data-main" work?
Asked Answered
F

1

18

For example requireJS uses following syntax:

<script data-main="scripts/main" src="scripts/require.js"></script>

and in its documentation you can read:

data-main attribute tells require.js to load scripts/main.js after require.js loads

  1. How is that (script load-order) possible?
  2. If the name of the js-file was nomain.js, would the data-attribute be "data-nomain" ?
  3. I see no information about that in the html5 specification or am I looking at wrong place?

thank you

Finkle answered 29/9, 2015 at 8:40 Comment(1)
This is why "foo" and "bar" were invented, to distinguish user names from system names.Selfliquidating
T
24

How is that (script load-order) possible?

Because that is the purpose of require.js which consists of rather a lot of code to do that.

That specific part is rather trivial, require.js can't do anything (including load another script) until it is loaded itself.

If the name of the js-file was nomain.js, would the data-attribute be "data-nomain" ?

No. Require looks at data-main to determine the entry point script file. It gets the URL from the value of that attribute.

I see no information about that in the html5 specification or am I looking at wrong place?

data-* attributes are defined in the section 3.2.5.9 Embedding custom non-visible data with the data-* attributes

Tahitian answered 29/9, 2015 at 8:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.