javascript - Why should I put external resources in the html head? -
I like to know that people say "put external resins on the head of the page", such as: Should these resources be added only on the page when it requires those resources? For example, while programming on PHP, if I have a page that requires some CSS instead of the other, then this I get many suggestions on the forum / community which put everyone in the head ... What can you say? There are two things, and I'm not sure about what you are asking about. is saying that they For this, it should be in only those pages for which they need or not, for the purpose that your pages A script in First of all, suppose that 90% of the announcements of a CSS stylesheet are used on all pages on the site (it is self-contained). Of a well-designed style). We can keep only 10% of the other 10% separate files for a few pages, and actually 2% at one time, 3% in the second and one in 5% or something That's it. However, since every URI arrives F is at the top of the bandwidth to download the actual stream, so we add probably reflected the more you lose. caching here and it is a clear winner keeping a file. On the other hand, it is said that there is a set of resources in such sites that others need a very different style. In this case, different CSS may be as big or as big as before, so it is more understandable Comes in as a separate file only where necessary is used (also, this cascade can ride more in work, for example if the "main" stylesheet gives blue background, then the second one You can give background and we indicate that we need to know whether it is a stylesheet or not, without having to set different classes in related HTML pages.) The same applies to Javascript Some functions are rarely used in "normal" JavaScript files, but for a single page use only a large set of work will almost certainly be loaded into it. Should page He said, we can choose to include another JS in a relatively light page which is likely to hit before a heavier page, which will be used to take advantage of caching. Later, I will consider more fully the optimization of a site compared to the design of that site (considered as a separate page, the second JS is clearly useless). EDIT: Finally, all these items have the simplicity of dealing with the same file, and in some additional downloads, waste can be justified with less maintenance. & lt; Head & gt; & Lt; Script type = "text / javascript" src = "settings / myJavascript.js" & gt; & Lt; / Script & gt; & Lt; Title & gt; Title & lt; / Title & gt; & Lt; Meta http-equiv = "content-type" content = "text / html; charset = UTF-8" /> & Lt; Link type = "text / css" rel = "stylesheet" href = "settings / style.css" title = "style" media = "all" /> & Lt; / Head & gt;
link type or
script src that page Without loading everything on top, right?
& lt; Head & gt; , this can mean the opposite of elsewhere in the document. Some people put CSS links in the body, even if they are not allowed there, and whenever
& lt; Script & gt; It is almost always a good idea to head (and in those cases where it should not be clear, and even with the exception of cut-paste scripts related to other services, To work better than the head, it can be rewritten, where Amazon gives you
Comments
Post a Comment