HTTP Performance Tuning

When we talk about the HTTP performance of a web site or a web page mostly we regard to the speed the content delivered. If we summarize all the parameters of the web performance we can stick to these 3 golden rules in order to gain high performance.

  • Reduce the number of HTTP calls (Reduce the number of requests to the server)
  • Reduce the size of the content in the requests
  • Send information infrequently

These are some common practices to boost up HTTP performance.

HTTP Compression – Most of the web servers support this option. HTTP compression can be static or dynamic. In the static HTTP compression web server saves the compressed version of the content files such as CSS and Javascript. In the Dynamic compression the response HTML is compressed and sent to the client. Dynamic compression works well but eats up more CPU in your web server. Mostly static compression is configured in the web servers by default

Minification – This is a well known method for the Javascript developers. We can do minification to CSS files as well. We reduce the size of the files by removing comments, white spaces, shrinking variable names and ect. There’re plenty of Javascript minification tools available online. jQuery.min is the best example for this type.

Content Expiration – This is the cache in the browser. Browsers check for the new versions of the files and they download the files only when a new version is available. This is good since it reduces the size of the calls to the server, but if you have many small files and the browser goes on checking all of them it will be a performance hit. So better include your files in the relevant folders and set the expiration to the folders.

Content Delivery Networks – CDNs are well known and highly used by many. Geographically distributed so this reduces the travel time of data. CDNs are mostly used to deliver the static content.

Image Optimization – By optimizing the images we can reduce the size of the requests. JPEG and PNG are the heavily used file formats in the web. There are plenty of image optimization tools available. JPEG Tran for the JPEG images and PNG Crush for the PNG images are widely used and light weight.

Advertisement

WinRT or WinMD Components

The WinRT platform provides developers with a new way to build reusable software components. WinRT types packaged in a WinRT component, also called a WinMD component (WinRT components == WinMD components). In traditional .NET application development, you could create a dynamic-link library (DLL) as a managed class library and use it in one or more applications.

This option is still available in Visual Studio. However, you can change the output type of a library project from class library to WinRT component, and the output of such a project is a WinMD (Windows Meta Data) file.

 

Benefits of creating a WinMD / WinRT component.

Contrasting to the DLL files WinRT / WinMD components can be accessed by unmanaged languages like C++ and Javascript. This allows us to create a WinRT / WinMD component in a managed language (C# or Visual Basic) and use it across different Windows Store Apps (WSA) projects implemented in unmanaged languages.

But this flexibility comes with some restrictions.

  • All public classes in WinRT / WinMD component should be marked sealed.
  • public fields aren’t allowed.
  • public data members must be declared as properties
  • Data types should be WinRT / WinMD compatible
  • Creating a WinRT / WinMD component in C++ has some additional property attribute settings (activatable class and ect…)

 

Creating a WinRT / WinMD component in C#

This is a very simple example and straight forward create Windows Store Apps (WSA) class library. Mark the class public and sealed. Create a method to return a string value.

image

Go to Project Properties and change the output type from Class Library to Windows Runtime Component. 

image

Component Code image

 

 

 

Do the build.

Accessing the C# WinRT in Javascript

Create a WSA project in Javascript. Add the WinRT project reference to the Javascript project.

Create a Javascript method to call the WinRT method. VS intellisense would guide you.

Javascript Code.

image

Here you can notice that the GetDate() C# method is formatted to getDate() with Javascript naming convention.

HTML Code

image

Run the code. 🙂

Things to consider

When you create a WinRT / WinMD component it is specifically designed for the Windows Runtime. Windows Runtime supports different language executions. In the above Javascript project we have a WinRT component developed in C# executed in the Javascript app. This is very useful when you want to extend your existing LOBs. You can use your existing managed code with little modifications, this cuts down development cost.

And also some complex data processing codes are hard to be written in pure Javascript. You can implement those in C++ and use the component in your front facing Javascript WSA.