I want to create a modular website with no frameworks or CMS nor server-side language. Also, I am doing simple use of the hashchange event to help the navigation.

The structure would be as follows:

  • A basic container HTML page with 3 main areas: header, content, footer.
  • Individual HTML files - one for each page - which would contain only the HTML to be inserted in the content part
  • a JavaScript file with all the code needed
  • a CSS file with all the styling

Please bear in mind that all the code below has been cleaned to illustrate the concept: the real code is more complex (e.g. the content of the header and the footer might as well be loaded with AJAX calls, some manipulations might occur to the DOM after the content has been put in place, handling AJAX failures, and so on).

A sample version of the HTML for the container page would be like:

<!DOCTYPE html>
    <meta charset="utf-8"/>
    <title>Faux SPA</title>
    <link rel="stylesheet" href="styles.css"/>
    <script src="script/jquery/jquery-1.12.4.min.js"></script>
    <script src="script/loader.js"></script>
    <div id="viewPort">
        <div id="header">
        <div id="content">
        <div id="footer">
    <button onclick="setPageHash('Page1')">View 1</button>
    <button onclick="setPageHash('Page2')">View 2</button>

A couple of sample HTML files for the content (obviously, the real-world content would be more complex):


    <img src="images/Image1.png" alt="">

And Page2.html:

    Some text content 
    second line of text content 

Finally, the JavaScript code would be like:

var validHashes = ["Page1", "Page2"];
function page(pageName){
    var newPageURI = pageName + ".html";
    var container = "#content";
        function(content) {
            putContentInContainer(container, content);
function putContentInContainer(container, content) {
function loadPageFromHash() {
    var hashValue = window.location.hash || "";
    var hashIsValid;
    hashValue = hashValue.replace('#','');
    hashIsValid = (validHashes.indexOf(hashValue)>=0);
    if (hashIsValid) {
    } else {
        console.error("no valid HASH!");
function setPageHash(page) {
    window.location.hash = page;
window.onhashchange = loadPageFromHash;
$().ready(function() {

So, my questions are:

  1. Is there any disadvantage in loading the HTML this way?
  2. I know that the HTML files with the content will not be valid HTML files because of the missing tags (e.g. body, html, etc.): would that represent a problem?
  3. Is there anything else I am missing for the whole hashchange subject?
  • \$\begingroup\$ Welcome to code review. What I see here doesn't handle mobile devices very well. Hard coding the dimensions into the HTML prevents responsive design. The HTML should also contain a no script section informing users that disable scripting that they won't get the best user experience. \$\endgroup\$
    – pacmaninbw
    Commented Aug 25, 2016 at 13:54
  • \$\begingroup\$ @pacmaninbw: what I am interested here is about loading the content and handling the url change. As already said, this is a simple HTML page just to show the concept, of course all the styling will go in separate CSS files. i'll edit the code to remove it, though, so that it doesn't get in the way... \$\endgroup\$
    – Pierpaolo
    Commented Aug 25, 2016 at 14:09

1 Answer 1


1) Loading HTML this way will exclude all your users with js disabled from browsing your site, that's why back-end scripting exists
2) They are not a problem if you inject them in a valid HTML document. If you don't, the majority of modern browsers will create html, head and body elements by themselves, but all the other browsers will possibly display nothing
3) Theoretically not

  • \$\begingroup\$ Thanks for the comments. Regarding point 1, though, good one but the "meaty" part of the website will be an interactive map created with OpenLayers 3, so without javascript there really is no point in browsing the website... \$\endgroup\$
    – Pierpaolo
    Commented Aug 25, 2016 at 13:13
  • 1
    \$\begingroup\$ @Pierpaolo In your basic HTML landing page you should have a no script section that informs users with scripting disabled that they won't get the best results. \$\endgroup\$
    – pacmaninbw
    Commented Aug 25, 2016 at 13:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.