Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do we use <script> for scripts, but not <style> for external CSS?

A relative of mine who started to learn Web Development asked me this question.

Why <script src="min.js"></script> and <link rel="stylesheet" href="min.css">? Why not <style href="min.css"></style>. Why do we use link tag to add external CSS in the page but when we link CSS to page but we use <style>...</style> when we write CSS inside <head>?

I told him that it's because of spec. Is there any more info to give to him?

like image 417
Jitendra Vyas Avatar asked Aug 19 '11 13:08

Jitendra Vyas


People also ask

What is the difference between script and style element?

Style and script are two calls that alert the browser of what is coming next. Style means just that how a site looks and script is what a site does or line of code.

What is the purpose of the script and </ script tags?

Definition and UsageThe <script> tag is used to embed a client-side script (JavaScript). The <script> element either contains scripting statements, or it points to an external script file through the src attribute. Common uses for JavaScript are image manipulation, form validation, and dynamic changes of content.

Should scripts be inside or outside body?

The <script> Tag You can place any number of scripts in an HTML document. Scripts can be placed in the <body> , or in the <head> section of an HTML page, or in both.

Why do we need external CSS and JavaScript files?

The first major benefit of using external CSS style sheets and external JavaScript files is faster load times for your web pages. According to an experiment at Google, even a half a second difference in page load time can make a 20% difference in how much traffic that pages retain.


1 Answers

It's historical... coincidence? You can recommend him reading part about Past of diveintohtml5.info, where there are some interesting stories, actually mail correspondences, between web developers. Web developers means they were, in fact, developing the Web we see nowadays ;)

I.e. <img> tag we are used to:

<IMG SRC="file://foobar.com/foo/bar/blargh.xbm"> 

could be:

<ICON name="NoEntry" href="http://note/foo/bar/NoEntry.xbm"> 

or

<A HREF="..." INCLUDE>See photo</A> 

or

<INCLUDE HREF="..."> 

but finally devs decided to stick with <img>, which was already implemented:

We’re not prepared to support INCLUDE/EMBED at this point. … So we’re probably going to go with (not ICON, since not all inlined images can be meaningfully called icons). For the time being, inlined images won’t be explicitly content-type’d; down the road, we plan to support that (along with the general adaptation of MIME). Actually, the image reading routines we’re currently using figure out the image format on the fly, so the filename extension won’t even be significant.

I don't know direct answer to your question, but I'm pretty curious about <link> tag, too. Finding answer would probably include some web archives digging.

like image 155
Xaerxess Avatar answered Sep 29 '22 21:09

Xaerxess