简体   繁体   中英

Are ASP.Net Control IDs bad for SEO and page size?

ASP.Net controls (eg asp:Label) generate messy html ids (eg ct100_ct100_Yabba_Dabba_Doo_FinallyTheRealId). Yeah, they're ugly, but someone told me today that they're also:

  1. unfriendly for SEO
  2. increase the page size

I half believe 1) and half disbelieve. I know that certain id names (eg "header") are keywords that search engines will use to generate meta information, but I'm more skeptical that a span with id="author" really affects SEO. I'm willing to admit that I could be wrong.

On point 2), I'm at least 90% skeptical. Most of page size is not the html characters and I truly wonder if 100 longer ids would even add 1kb to a page size.

I can go with one of two approaches. Which approach would you take?

Approach 1)

<asp:Label id="lblAuthor" runat="server"></asp:Label>

with code behind

protected void Page_Load(object sender, EventArgs e)
{
   lblAuthor.Text = "Superman";

or Approach 2)

<span id="author"><%# Eval("Author") %></span>

with code behind

public string Author { get; private set; }
protected void Page_Load(object sender, EventArgs e)
{
       Author = "Superman";

On the one hand, 1) doesn't generate the nasty ids. On the other hand, I've always hated untyped strings in asp.net web forms and avoided them when I can. Also, if a page has 30+ elements, I end up with 30 page properties, which makes me feel uneasy. (Side note: a reason to love how the model works in the MVC pattern).

We're working in .Net 3.5.

What are your thoughts?

Thanks.

Approach 3)

<span id="author"><asp:Literal id="author" runat="server" /></span>

Code behind:

author.Text = "Dr. Seuss";

asp:Literal is what the name implies, a control that renders only the text you send it; no more, no less.

Approach 3)

<span id="author"><asp:Literal id="litAuthor" runat="server" /></span>

with code behind

protected void Page_Load(object sender, EventArgs e)
{
   litAuthor.Text = "Superman";
}

this solves you id problem with Labels. For other elements, good luck ;)

SEO: No

Page size - SURE. I mean, the strings are longer, so they take more space, so page size if longer.

Update to .NET 4.0 then you can override the ID's with stable short ID's.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM