0

I have static HTML files, each looks like the following.

<!DOCTYPE html>
<html>
<head>
    <title></title>
    <meta charset="utf-8" />
    <style type="text/css">
    p {
        width: 100px;
    }
    </style>
    <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
    <script src="https://code.jquery.com/jquery-1.12.4.js"></script>
    <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
    <script>
        $(function () {
            $("#accordion").accordion();
        });
    </script>
</head>
<body>
    <div id="accordion">
        <h1>Chapter 1</h1>
        <p>dul tank ksk sk skek kejk jk sk sksjk sdsfkdsfs ai nvnei kdsfue v sjksfspas ksdsjkfs fsakd;afksajf;akd fa</p>
        <h1>Chapter 2</h1>
        <p>dul tank ksk sk skek kejk jk sk sksjk sdsfkdsfs ai nvnei kdsfue v sjksfspas ksdsjkfs fsakd;afksajf;akd fa</p>
    </div>
</body>
</html>

Because

    <meta charset="utf-8" />
    <style type="text/css">
    p {
        width: 100px;
    }
    </style>
    <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
    <script src="https://code.jquery.com/jquery-1.12.4.js"></script>
    <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
    <script>
        $(function () {
            $("#accordion").accordion();
        });
    </script>

is the common code, I want to extract it and put into a new file named common.html.

Question

I try load common.html with link tag but it produces a strange output.

<!DOCTYPE html>
<html>
<head>
    <title></title>
    <meta charset="utf-8" />
    <link rel="import" href="common.html"/>
</head>
<body>
    <div id="accordion">
        <h1>Chapter 1</h1>
        <p>dul tank ksk sk skek kejk jk sk sksjk sdsfkdsfs ai nvnei kdsfue v sjksfspas ksdsjkfs fsakd;afksajf;akd fa</p>
        <h1>Chapter 2</h1>
        <p>dul tank ksk sk skek kejk jk sk sksjk sdsfkdsfs ai nvnei kdsfue v sjksfspas ksdsjkfs fsakd;afksajf;akd fa</p>
    </div>
</body>
</html>

What is the proper way to load?

2 Answers 2

2

You can't include HTML code just by linking it that way.

If you want to have a templating engine managing your website either go for a flat website generator like Jekyll, use a framework such as Ruby on Rails or Symfony or roll out your own (using php, for instance).

Sign up to request clarification or add additional context in comments.

3 Comments

I have to use static HTML files.
Then Jekyll is a good way to go. Check their templating feature here.
Hey, @SingleFighter, any luck with this? Did you settle for a specific technology in the end?
1

Check out Jekyll. It is a static webpage generator. https://jekyllrb.com/

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.