BLOG: Embedding or Attaching?


You have two methods: embedding and attaching. Which is better?

The answer is, attaching. By far.

I like attaching scripts and style sheets. It allows me to use the same script file or style sheet on as many Web pages as I want, which is invaluable for frequently used functions like rollovers or popup menus and sitewide styles. If I tried to embed these things, I'd have to copy and paste the same blocks of code over and over again onto each and every page that requires them. This seems to me like a waste of time, not to mention bandwidth. The visitor's browser has to load the embedded stuff again and again, while the browser caches attached files.

Even more importantly, if I want to change something late in the process, I only have to fix it once, in the attached script or style sheet. When you embed everything, you have to go through every instance of the code and make the same corrections over and over again. Another needless waste of time.

Besides, for those who strive for per-spec implementation, the W3C recommends that you attach rather than embed.

Bottom line: Embedding is fine for quick, one-shot functions and styles. For anything you might want to reuse, attaching is the only way to fly.



Web Design Garage
Web Design Garage
ISBN: 0131481991
EAN: 2147483647
Year: 2006
Pages: 202
Authors: Marc Campbell

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net