HTML: How to set up web page head and body with external file references

1.6k views Asked by At

I am new to HTML and programming and hope someone can help me with this.

I have written the code for the first pages of my website and am now about to upload these to the server for a test.

Therefore I would like to know if the basic structure of my documents is correct and would like to get some comments on the following:

  1. Should I add or change anything regarding my document's head ?
  2. Do I include the external style sheets the right way and at the right position + is it correct to start the href with "/" here ?
    (I read CSS should be included before JS for better performance.)
  3. Do I include the external JS and jQuery references the right way and at the right position ?
    (I read JS should be included at the end of the body for better performance.)

Notes: All PHP / HTML pages of my website are saved as separate files in the same folder. This folder also contains a sub folder "includes" where my stylesheet and functions file are saved.

My HTML structure:

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <meta name="author" content="John Doe" />
        <meta name="description" content="Created: 2015-06" />

        <base href="http://www.myURL.com/" target="_self" />

        <!-- jQuery -->
        <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js" type="text/javascript"></script>

        <!-- CSS -->        
        <link rel="stylesheet" type="text/css" href="includes/styles.css" />
        <!-- CSS - Font Awesome -->
        <link rel="stylesheet" type="text/css" href="//maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css" />

        <title>My Page</title>
    </head>

    <body>
        <!-- ... -->
        <footer class="footer">         
            <!-- ... -->
        </footer>

        <!-- JavaScript -->
        <script src="includes/functions.js" type="text/javascript"></script>
    </body>
</html>

Many thanks in advance, Mike

1

There are 1 answers

2
light On BEST ANSWER
  1. Looks good. Just a couple of minor things:

    • You should add <meta http-equiv="X-UA-Compatible" content="IE=edge"> to ensure you don't get any MSIE compatibility mode issues.

    • You may add favicon definitions in the head.

  2. Yes, stylesheets belong in the head. The href depends on where you are storing the css files.

    • If you want to include a stylesheet in the same folder as your HTML file, use href="styles.css"
    • If you want to include a stylesheet in another folder, e.g. [css] folder, use href="css/styles.css"
    • If you have HTML files in various folders and you don't want to rewrite your hrefs all the time for each HTML file, you can start the href with a slash to indicate search should start from the "root" of the server, e.g. href="/css/styles.css"
  3. Move ALL your JS (including jQuery) to the bottom of the page, just before the closing body tag. Unless there's a very strong reason why you need JS to run before the page starts displaying, you should not have JS in the head.

There are a lot of things to learn, but it can be very fun and rewarding. Hope you have an enjoyable programming experience ahead. :)