Click here to Skip to main content
13,198,325 members (86,195 online)
Click here to Skip to main content


78 bookmarked
Posted 5 Feb 2009

ASP.NET Custom Control for High Performance Web Scripts

, 13 May 2009
Presents a custom control replacement for the script tag that optimizes JavaScript for web pages. Automatically merges, prevents duplicates, externalizes, orders, adds expires headers, caches, minifies, and places your scripts.
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ExternalizeJavascriptTest.aspx.cs" Inherits="HighPerformanceScript.Tests.ExternalizeJavascriptTest" %>
<%@ Register TagPrefix="HP" Assembly="HighPerformanceScript" Namespace="HighPerformanceScript" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

<html xmlns="" >
<head runat="server">
  <title>Externalize JavaScript Page</title>
  <form id="form1" runat="server">
    <HP:Script runat="server">
      var span1 = document.getElementById("Script1Target"); = "#00ff00";
      span1.innerHTML = "PASS";
    <HP:Script runat="server">
      function FirstScript() {
        var span = document.getElementById("Script2Target"); = "#00ff00";
        span.innerHTML = "PASS";
    Tests inline scripts that are automatically externalized. <br />
    <HP:Script runat="server">
      var scripts = document.getElementsByTagName("script");
      if(scripts.length == 2) { // one for all external, one for internal test.
        var span = document.getElementById("Script3Target"); = "#00ff00";
        span.innerHTML = "PASS";
    <span id="Script1Target" style="background-color: red;">FAIL</span> Inline script is run.<br />
    <span id="Script2Target" style="background-color: red;">FAIL</span> Multiple scripts are kept in order.<br />
    <HP:Script runat="server" Location="Inline">
      document.write("<span style='background-color: #00ff00;'>PASS</span>");
    Inline script is left alone.<br />
    <span id="Script3Target" style="background-color: red;">FAIL</span> Only single tag is output.<br />

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Adrian Akison
Team Leader Zuuse Pty Ltd
Australia Australia
I have been a professional software developer for twenty years, starting with C++ and migrated to C#. While I have transitioned into full time management, writing code is still my passion. As I don't write code for work very often, I have had the opportunity to apply my programming skills as a hobby where I have recently authored two Windows 8 store apps. First, an Asteroids tribute game, 'Roid Rage and most recently Shared Whiteboard (which does what it says).

I make a habit of contributing production code to every project I run. Most notably, I have recently run teams to build The Navigator for The Advertiser newspaper and Street Lights Out for SA Power Networks.

You may also be interested in...

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.171020.1 | Last Updated 13 May 2009
Article Copyright 2009 by Adrian Akison
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid