Googlecom an example of minied library is yuis pure at

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: ype="text/css" title="alt2" media="screen" /> function changeStyle(title) { var lnks = document.getElementsByTagName('link'); for (var i = lnks.length - 1; i >= 0; i--) { if (lnks[i].getAttribute('rel').indexOf('style')> -1 && lnks[i].getAttribute('title')) { lnks[i].disabled = true; if (lnks[i].getAttribute('title') == title) lnks[i].disabled = false; } } } <span onclick="changeStyle('alt2')">Switch to second alternative stylesheet</span> Copyright 2009 - 2013 Horowitz 19 Rule 6: Move Scripts to the Bolom •  As the loading of JavaScript can cause the browser to stop rendering the page unOl the JavaScript is fully loaded, one can avoid the delay by moving scripts to the bolom •  A second opOon is the defer alribute <script type="text/javascript" defer="defer"> some script .... </ script> •  Defer indicates that the script is not going to generate any document content. The browser can conOnue parsing and drawing the page Copyright 2009 - 2013 Horowitz 20 Rule 7: Avoid CSS Expressions •  Used to set CSS properOes dynamically in IE Width: expression(document.body.clientWidth < 600 ? “600px” : “auto”); •  Problem: expression may execute many Omes –  Mouse moves, key press, resize, scroll, etc •  AlternaOves –  One- Ome expressions –  Event handlers •  Expression overwrites itself <style> P { background-color: expression(altBgcolor(this)); } </style> <script> function altBgcolor(elem) { elem.style.backgroundColor = (new Date()).getHours()%2 ? “F08A00” : “#B8D4FF”; } </script> Copyright 2009 - 2013 Horowitz 21 Rule 8: Make JS and CSS External •  JavaScript can be placed inline, e.g <script type=“text/javascript>var foo = “bar”; </script> •  Or as an external script, e.g. <script src=“foo.js” type=“text/javascript”></script> •  Placing JavaScript and CSS inline makes the docu...
View Full Document

This note was uploaded on 01/29/2014 for the course CSCI 571 taught by Professor Papa during the Spring '07 term at USC.

Ask a homework question - tutors are online