问题
Is it a bad practice have non-HTML tags of the page? I need to use them for internal content processing needs and wonder if there are any troubles with it (SEO for example)?
回答1:
Yes it is bad. Not particularly for SEO but for browsers. You are relying on the browser to ignore your tags and render the page correctly. Since every rendering engine loads a page slightly differently, you have no way of knowing how it will handle your bad html.
Can you wrap them in html comments? Like so:
<!--<not a real tag>-->
The browser and spiders will ignore these but since they are still part of the html, your parser might still be able to read them.
An alternative is to use HTML5's custom data attributes. Your parser should also be able to read these.
W3C also have an experimental custom elements spec. Browser support looks poor at present but this may be of interest in future.
回答2:
Yes, it's bad for browsers (and a little for SEO). Each browser could interpret a random tag on its own way.
If you need to do internal content processing, you can store your data in attributes of your existing HTML tags, with data-* attributes (HTML5 spec.), like this:
<div class="simple-div" data-file="./abc.txt" data-pattern="(.+)"></div>
<a href="javascript:void(0)" data-objID="42">My link!</a>
The HTML document shouldn't store data anyway.
回答3:
I dont know what you want to do specifically, but you could use an invisible div or hidden field with custom data attributes? or even a comment?
来源:https://stackoverflow.com/questions/17923853/are-non-html-tags-in-a-html-document-bad-for-seo