Inline style raises additional request

On_Load is called twice per page. After using Firebug, I found that it asks for

http://localhost/default.aspx

then it does another request

http://localhost/default.aspx#ced3db

I search "#ced3db"

and found it in <table>

on the page. When I remove its background attribute, the problem goes away.

<table width="430" height="281" border="0" 
    background="#ced3db" cellpadding="0" cellspacing="0">

      

I used the style attribute to avoid asking the page twice. But I still need to know: why are there two queries? I would like to understand the main reason to avoid re-requesting the page as it can slow down any website.

Edit: The question has nothing to do with inline styles and the use of CSS files. It's about avoiding inadvertent re-request of the page for performance reasons.

Note: On_Load can be called twice for several reasons, see ASP.NET Page.OnLoad is executed twice

  • AutoEventWireUp is true and you are overriding On_Load.
  • The custom control contains AutoEventWireUp with true. Haven't tried this.
  • The page or home page contains <img src="#"> or <img src="">

+3


source to share


2 answers


I'm pretty sure the attribute background

on the element is table

expecting an image url. (I don't think this is even the correct attribute for this element, or at least I've never seen one use it. May have browser-specific behavior.)

If so, then it makes sense. At the end of the question, you will notice:

  • The page or master page contains <img src="#">

    or<img src="">



So this is similar to what's going on here. The browser interprets this color tag as a URL and returns a request to the server resource to try to fetch it, since the hash URL itself matches the current page by default. In an anchor tag, it will just give focus to that tag on the page, but in the resource link tag (for example img

, but in this case there will be an attribute table

that the url expects), it has to make another request.

Update: . A little search on the attribute brings up several pages similar to this one that seem to indicate that it expects a URL.

Indeed, the element table

does not seem to officially have an attribute background

. At least not in HTML 4 or HTML 5 .

+3


source


The attribute background

does not accept hexadecimal colors as inputs. You should still use CSS. Use CSS property instead background-color

.

See this fiddle for an attribute background

not working.

http://jsfiddle.net/SrEDB/



And it works with the CSS property.

http://jsfiddle.net/SrEDB/



-1


source







All Articles