开发者

How to define priority to load resources on the webpages?

Is there any way to define priority for resources in web pages. e开发者_JAVA技巧.g. If define the particular css,js or image load first on the web page. Development Language PHP

Thanks


Is there any way to define priority for resources in web pages

Not really, at least not 100%.

JavaScript files are loaded and executed in the order they are specified.

CSS style sheets are loaded asynchronously. That means they load in parallel to other resources, and they are done when they are done. The same goes for images.

If you need to do something after all style sheets and images have loaded, you could use the JavaScript onload event.

More about what is executed/loaded in which order in this brilliant answer.


PHP is executed on the server side and acutally outputs HTML (so your browser does not even know there is PHP behind).

Then, resources (html, CSS, javascript, images) are loaded by your browser, speed depending on the browser, connection speed, resources (mainly javascript and images) weight...

The resources are loaded in the order in which you write your HTML page (i think). Javascript will be loaded when page loads, so if it's heavy you may have slow loading speed.

On the contrary, image are usually loaded AFTER the page (if width and height are supplied, the browser can load the rest because it knows that the image will take the given space).

I'm not sure about the reste, and whan happens when including external stylesheet and javascript though...

Hope it helps !

[EDIT] AH ! Seems i was write, loading order is as the page is written. http://fr.w3support.net/index.php?db=so&id=473628

BUT... for javascript, if you use libraries likes jQuery (their are many others), you use a "DOMReady" event which only loads Javascript when the page (HTML & CSS stuff) are fully loaded.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜