开发者

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

ASP.Net controls (e.g. asp:Label) generate messy html ids (e.g. 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 (e.g. "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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜