How to setup an ASP.Net/IIS Web Application to serve static content from a cookieless domain

105 Views Asked by At

In my quest to get the best performance for an ASP.Net/IIS based web application, I would like to have static content be served up from a cookieless domain as suggested by Google.

I have followed this discussion and understand how it would work. Stopping cookies being set from a domain (aka "cookieless domain") to increase site performance

What I fail to understand is how to have the image/js/css files' src point to the new domain name instead of the one resolved by the browser when served up from the original web application.

Here is what I mean -

Original Web Application in IIS at myapp.mydomain.com Cookieless Web Application in IIS at static.mydomain.com img tag in a web page is served to the browser from the original Web Application as src="Images/someimage.jpg" which the browser automatically resolves to myapp.mydomain.com/Images/someimage.jpg

The problem for which I am looking for a simple and a smart solution -

Across the application, how do I get the img and asp:image to serve absolute URLs instead of the relative URLs. i.e. have the img tag get the absolute URL as src="//static.mydomain.com/image/someimage.jpg"

PS: I have also referred to How do I setup IIS with a cookieless domain to improve performance? and lot of similar contents, but all of these are tell you what is to be done, but not the how to implement at the ground level.

1

There are 1 best solutions below

1
On

You will have to provide the fully qualified url:

src="//static.mydomain.com/image/someimage.jpg"

or

src="http://static.mydomain.com/image/someimage.jpg"

I don't see any other way around it.