Gayan
Gayan

Reputation: 2871

asp:image or img

Does asp:Image tag perform faster than normal HTML img tag?

I have 20 images to show on a web page (tiny images) and I have no idea which one to use.

Upvotes: 2

Views: 5382

Answers (5)

Meligy
Meligy

Reputation: 36624

The img tag will be faster for sure because no server side processing and not have ViewState (which can be disabled still).

Typically if you don't need to set properties dynamically don't use <asp:Image ... />

Remember you can always do something like:

<img src='<%= MyPathMethodInCodeBehind("some value") %>' 
     alt='<%= MyClass.SomeMethod(someParam) %>'              />

However, the difference is really small and would argue it's not notable, yes, even for 20 images.

Upvotes: 0

Robert Koritnik
Robert Koritnik

Reputation: 105081

On server-side

HTML elements in usual use (without setting runat="server" on them) are always faster compared to server-side counterparts, because they don't execute any additional server-side logic or consume other resources. They also don't add anything to page's view state.

On client-side

Simple server-side controls (those that translate to a single HTML element) are no different to normal HTML elements. But complex server-side controls (like calendar) are complex in terms of HTML element quantity thus require some additional browser resources. But making the same thing/functionality with usual HTML would create more or less similar results. So we can assume on the client-side speed is the same.

Verdict

Use server side controls only when you need to add some server-side processing to it. If not, rather use plain-old-HTML-controls. They will be processed faster on the server, will not add anything to view state and will work with the same speed on the client as their server-side counterparts.

This is true for any HTML element that has a server-side equivalent (like img that has asp:Image on the server side). When there's no client-side equivalent (like calendar) you have to of course use server side controls or use some client-side library that provides such functionality (jQuery has a date picker for instance). But you have to know Asp.net processing quite well to combine the two effectively.

Upvotes: 9

Steve B
Steve B

Reputation: 37710

use asp:image only if you have to manipulate it on the server side (dynamically setting the title, source, visible, etc).

since asp:image is "running" at the server side, it consumes a bit of memory and cpu usage.

Upvotes: 2

driis
driis

Reputation: 164341

Use an <img /> tag if you don't need to interact with it programmatically. That's less overhead (although the overhead of using asp:Image is minor).

Upvotes: 1

Guffa
Guffa

Reputation: 700850

No, there is no performance difference at all when it comes to loading the images. The asp:Image control produces an img tag, so the result that arrives to the browser is more or less identical.

The asp:Image control is convenient if you want to control it's attributes from the code behind.

Upvotes: 0

Related Questions