Click here to Skip to main content
15,894,896 members
Articles / Web Development / CSS

A Smarter Way to Include JavaScripts and CSS to Reduce Page Load Times

Rate me:
Please Sign up or sign in to vote.
4.78/5 (31 votes)
17 Apr 2011MIT5 min read 97.1K   819   98  
Reduce the number of HTTP requests required to render the page, resulting in faster page loads by combining and compressing multiple JavaScripts into one JavaScript file and multiple CSS files into one style sheet file.
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="TestApp._Default" MasterPageFile="~/MySite.Master" %>
<%@ Register TagPrefix="smart" Namespace="Kaliko.SmartInclude" Assembly="Kaliko.SmartInclude" %>

<asp:Content ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <smart:IncludeScript Url="originals/jquery-1.3.2.js" runat="server" />
    <smart:IncludeScript Url="originals/WebResource.js" runat="server" />
    <h1>This is a test page</h1>
    <h2>Javascript</h2>
    <p>The following javascripts have been included as a single and compressed file (67kB minified, 25kB minified & GZip-compressed):</p>
    <ul>
        <li>jquery-1.3.2.js (118 kB)</li>
        <li>WebResource.js (21 kB)</li>
    </ul>
    <h2>Style sheet</h2>
    <p>The following stylesheets have been included as a single and compressed file (24kB minified, 5kB minified & GZip-compressed):</p>
    <ul>
        <li>jquery-ui-1.7.2.custom.css (27 kB)</li>
        <li>Styles.css (3 kB)</li>
    </ul>
</asp:Content>

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.

License

This article, along with any associated source code and files, is licensed under The MIT License


Written By
Software Developer (Senior)
Sweden Sweden
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions