What is a static website generator?

Asked

Viewed 210 times

6

Recently I came across this theme, more precisely the tool Hugo, that basically builds sites from themes and Apis reminding a lot of Ruby on Rails.

I ran a test on build of an application that uses a static JSON for content listing, example:

products.json

[{
    "id": "1",
    "name": "Klingon dictionary",
    "price": 34.87,
    "image": "/images/dictionary.jpg",
    "description": "nIvbogh tlhIngan dictionary qaStaHvIS veng SuvwI'",
    "url": "http://snipcart-hugo.netlify.com"
}, {
    "id": "2",
    "name": "Captain Kirk Phaser",
    "description": "The Original Series Phaser comprises a small, hand-held Type I Phaser, which slots into a larger Type II Phaser body with a removable pistol-grip.",
    "price": 145.98,
    "image": "/images/phaser.png",
    "url": "http://snipcart-hugo.netlify.com"
}]

HTML

<div class="col s6">
    <h2 class="header">{{ .name }}</h2>
    <div class="card horizontal">
        <div class="card-image">
        <img src="{{ .image }}">
        </div>
        <div class="card-stacked">
        <div class="card-content">
            <p>{{ .description }}</p>
        </div>
        <div class="card-action">
            <button
                class="snipcart-add-item waves-effect waves-light btn"
                data-item-id="{{ .id }}"
                data-item-name="{{ .name }}"
                data-item-price="{{ .price }}"
                data-item-url="{{ .url }}">
                    <i class="material-icons right">shopping_cart</i>
                    Add to cart
            </button>
        </div>
        </div>
    </div>
</div>

When consulting the requests, the file products.json was not requested in client making clear the safety of working with JSON directly on DOM.

What is and how this kind of tool works?

  • 4

    It is a very cool thing, has several similar tools each with its characteristics. Many sites don’t need to be dynamic, they just need a generation structure. Why generate a page for each request if it "never" changes? Then you take the data from somewhere, a database, file, etc. and generate the static HTML and serve it performatively. Simple and efficient. Pity that many people do not see these things, just follow formulas. I’m making a blog that will work like this.

  • Very interesting this new look for web, when it is ready the blog link here :), by the way I think better answer the question, because hardly anyone will do it.

1 answer

5


There is a huge amount of tools like this, some are very sophisticated CMS, with the difference that the page to be viewed is not created at each request as is common.

Think about it, if a page practically doesn’t change, it doesn’t deliver something different to each user, to each access, so why create this page dynamically? The way it’s done in most Cmss is insane.

You can have all the CMS infrastructure, a database, data files, and generate the page every time it changes in some way. Then you change the processing need of the moment of reading the page to the moment there is written on it, which is very rare, many pages will never receive changes.

The generation takes place in much the same way that everyone knows, but instead of already having the server deliver for a request it writes to a file and/or keeps it in memory so that it is delivered ready every time there is a request. In fact in most cases you don’t even need to have an application serving it, you can generate HTML and leave it there as a static page, the difference is that there is a backend for your generation, it was not made in the hand. And it has a Dashboard for administration

It’s very simple to do this, very efficient and usually much safer.

The people don’t use it anymore because they don’t know the technique, which is naive, it’s not advanced. It’s that people don’t think to do it, they follow what they read somewhere and they don’t create anything, they don’t look for new solutions, they don’t weigh the alternatives, they’re not engineers.

In this case there is this JSON somewhere with the data needed to generate the page

But only with this excerpt it is not clear if this is what is happening, it seems that there is a request for JSON data on a static page and that the data is loaded dynamically, for this needs some script that does this load. It may be that this is one more SPA than static content.

  • I understood, in the example the data json are requested through the command {{ $products := getJSON "/data/products.json" }}, and yes, it is a SPA, but static, I do not know if this is possible because as I said, I am new to this subject, what I don’t really understand is that if I want any changes or add some section on the site, I will have to do only through the script?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.