.Net Web Developer Should Know?

1. Remove the HTTP Headers

By removing the header “X-Powered-By” you make a save around 29bytes for each requests, another reason as well you doesn’t want exposing stack trace.

Server: Microsoft-IIS/8.5
X-AspNet-Version:4.0.30319
X-AspNetMvc-Version:5.0
X-Powered-By:ASP.NET

<httpRuntime targetFramework="4.5.1" enableVersionHeader="false" />

    <httpProtocol>
      <customHeaders>
        <clear />
        <remove name="X-Powered-By" />
      </customHeaders>
    </httpProtocol>

 

//In Global put this
MvcHandler.DisableMvcResponseHeader = true;


2. Production
When you put the source code into the production you need to turn off the debug=”false” in the webconfig.
This will help to compilation of ASP become faster, code execute more faster and reduce more memory in used.

3. Enable Caching
Caching is one of the most important things, most of the times you doesn’t want anyone to keep download the image, css, js from your machine.

<system.webServer>
    <urlCompression doDynamicCompression="true" doStaticCompression="true" />
    <staticContent>
      <clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="7.00:00:00" /> <!-- Make it 7 Days -->
    </staticContent>
    <caching enabled="true" enableKernelCache="true">
      <profiles>
        <add extension=".css" policy="CacheUntilChange" kernelCachePolicy="CacheUntilChange" location="Client" />
        <add extension=".jpg" policy="CacheUntilChange" kernelCachePolicy="CacheUntilChange" location="Client"/>
        <!-- You can Add any static file in here -->
      </profiles>
    </caching>
</system.webServer

4. Bundling & Minification
In the past most of Web Developer try to use any method to minify their JS & CSS, by remove all the space using JSCompress or CSSCompress site. What they forget .Net provide the build-in features Under App_Start/BundleConfig.cs

        public static void RegisterBundles(BundleCollection bundles)
        {
            bundles.Add(new ScriptBundle("~/bundles/jquery",
                        "ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js").Include(
                        "~/Scripts/jquery-{version}.js"));

             bundles.Add(new StyleBundle("~/Content/css").Include(
                        "~/Content/style.css",
                        "~/Content/themes.css"));
        }

After register in the Bundling, all you need to do in the production server just need to turn off in the web.config

<compilation debug="false" targetFramework="4.5.1" />

After you done, when you trace the HTTP Stack it’s will show jquery been minify with less work done.

Advertisements

One thought on “.Net Web Developer Should Know?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s