ScriptDeferFilter

Pushes lines of Javascript code to the bottom of the page to improve user-perceived performance. See Yahoo's explanation on this technique.

Before
<html>
	<body>
		<p>Paragraph 1</p>
		<script type="text/javascript">
			alert("Hi!");
		</script>
		<p>Paragraph 2</p>
		<script type="text/javascript" src="/script.js"></script>
		<p>Paragraph 3</p>
	</body>
</html>

After
<html>
	<body>
		<p>Paragraph 1</p>
		<p>Paragraph 2</p>
		<p>Paragraph 3</p>
		<script type="text/javascript">
			alert("Hi!");
		</script>
		<script type="text/javascript" src="/script.js"></script>
	</body>
</html>

How to use

Enter the line below in the Global.asax's BeginRequest event:

if (Request.Url.LocalPath.EndsWith(".aspx")) Response.Filter = new ScriptDeferFilter(Response);

Credits

Code is based on Omar Al Zabir's ScriptDeferFilter used in PageFlakes.

Last edited Aug 28, 2010 at 3:32 PM by weiwong, version 5

Comments

No comments yet.