HTML <head> best practices [closed]

2020-05-16 02:56发布

There are <meta> tags and other things you can place in the <head> of your HTML document. What <meta> tags etc. and best practices do you make use of in your HTML document to make it more accessible, searchable, optimized etc.

12条回答
女痞
2楼-- · 2020-05-16 03:30

You'll want to put SCRIPT elements at the end of the page before the close of the BODY element. See http://developer.yahoo.com/performance/rules.html#js_bottom for details.

查看更多
乱世女痞
3楼-- · 2020-05-16 03:33

Besides the usual doctype, title, etc, I will try and provide you with some things I have learned and implemented that might be of assistance to you.

Firstly, remember that the title, for best user experience should have the most relevant sub section first. This is because it is usually displayed in the title bar/tab list/bookmark name. Consider this page title...

Stack Overflow - HTML head best practices

becomes Stack Overflow... (munched to save room in tab bar/bookmark list)

Now if you had 5 Stackoverflow tabs open (as I often do :P) then how would the user know which one is which?

Also note with CSS the cascading nature... So the order of these will matter. Same with Javascript, any dependencies on other external sites must be allowed for. I put mine in the head and havn't noticed a performance decrease. I put them there because it to me looks more tidy and logical. Though some other people will recommend putting the <script src=""> links in just before </body> so the browser won't temporarily stall... Just use whatever works best for your site.

Also a Meta tag of 'rating' with 'general' let's Net Filtering software know your site is safe for viewers of all ages (as long as it is, of course!)

I also use..

<link rel="start" href="/" title="Home" />

to let the browser know where the home of my site is. And for any browser prefetching systems, though I believe these are yet to be implemented by browsers without assistance of plugins.

Also consider the 'next' and 'prev' <link rel=""> if your pages are in a sequence of sorts.

查看更多
对你真心纯属浪费
4楼-- · 2020-05-16 03:35

There is a related question here that may help add some light regarding the order of the tags.

Generally my pages include the following:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
    <title>...</title>
    <meta name="Description" ...>
    <meta name="Keywords" ...>
    <meta name="Copyright" ...>
    <meta name="Author" ...>
    <meta name="Language" ...>
    <style type="text/css" ...>

DocType is important to enforce strict rendering (No quirks mode) by the browser. You may want to use XHTML instead - as long as there is one there. I add Copyright and Author purely because I design and create the pages for other companies. Description is for SEO, and Language is for the browser (if it supports it).

I don't believe it makes to much of a difference which meta tag comes first, or whether the title should be above. What counts in most cases is that it exists on the page, and has the correct content.

查看更多
女痞
5楼-- · 2020-05-16 03:35

Title, meta tags for keywords, content-type (if not explicitly set by the web server), and any CSS to be applied to the page.

Declaring the CSS up front allows the browser to lay out the page more efficiently (see http://developer.yahoo.com/performance/rules.html#css_top).

查看更多
迷人小祖宗
6楼-- · 2020-05-16 03:36

I would add an important note: if you're using IE's meta X-UA-Compatible tag to switch rendering modes for Interet Explorer, you must insert it as the first item in HEAD:

<head>
  <meta http-equiv="X-UA-Compatible" content="IE=7" />
  <title>Page title</title>
  ...etc
</head>
查看更多
萌系小妹纸
7楼-- · 2020-05-16 03:37

I didn't see this mentioned: the <base> tag, if specified, should be the first element in <head>. (The base URI of the document is assumed to be . before/if not specified.)

查看更多
登录 后发表回答