Closed szepeviktor closed 10 years ago
btw. is it a good idea?
http://dansajin.com/2013/01/25/ultimate-technique-inject-javascript/
is there measureable gain over a blocking <script>
tag?
Hey @szepeviktor!
It all depends on how your content (HTML) will arrive. If the content is arriving synchronously with the page (in other words: if the content is in the body element, rather than generated or templated by javascript), then you should use a blocking script to handle the className replacement. This could be in the <head>
or just before </body>
.
When I write apps that have content in the body, I generally put this type of code at the end of </body>
.
If your content is arriving async (generated or templated by javascript), then I like to put code like this inside thecurl([]).then()
callback.
-- John
btw. is it a good idea? http://dansajin.com/2013/01/25/ultimate-technique-inject-javascript/ is there measureable gain over a blocking
<script>
tag?
I believe that using curl.js's data-curl-run
attribute with an async
attribute (both on the <script>
that fetches curl.js) is faster than this code snippet. The reason is that his code snippet claims to wait for dom-ready (via setTimeout) before fetching curl.js.
Note, that the script in that blog post does not handle errors.
Here's the fastest way (afaict):
<head><!-- other stuff in here -->
<script async data-curl-run="path/to/run.js" src="path/to/curl.js"></script>
</head>
If you are concerned that fetching curl.js might slow down fetching of stylesheets in <link>
elements, then you could put it just before </body>
.
Closing this issue, but please continue to comment, if you wish!
-- John
Thank you!
Won't just before </body>
cause FOUT?
Yes, it could cause FOUT -- or it could prevent it. It all depends on which files are being loaded by HTML and which by JavaScript (and when).
nice support Thank you again!
Where/how should I put these statements to have them executed before content appears? (I know in the head, but is there a blocking way with curl to load/execute them?)