What is a static site generator?

4

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

I tested the build of an application that uses a static JSON for content listing, eg:

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 querying the requests, the products.json file was not requested in client making it clear the security in working with JSON directly in DOM .

What is and how does this type of tool work?

    
asked by anonymous 22.09.2017 / 15:37

1 answer

3

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 with every request as usual.

Think about it, if a page hardly changes, is not something different delivered for each user, for each access, so that you create this page dynamically?

You can have the entire CMS infrastructure, a database, data files, and generate the page every time it is changed in some way. Then you change the need to process the moment the page is read to the moment it is written to it, which is very rare, many pages will never receive changes.

The generation occurs in much the same way that everyone knows it, but instead of having the server deliver it to a request, it writes to a file and / or keeps it in memory so that it is delivered promptly every time there is a request . In fact in most cases you do not even need to have a serving serving this, 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 done in the hand.

It's very simple to do this, very efficient and often safer.

The staff no longer use this because they do not know the technique, which is even naive, there is nothing advanced. It is that people do not think to do, they follow what they read somewhere and do not create anything, do not look for new solutions, do not weigh alternatives.

In this case there is this JSON somewhere with the necessary data for page generation

But it is not clear from this section if this is what is happening, it looks like there is a JSON data request on a static page and the data is loaded dynamically, so you need some script to make this charge. This might be a SPA than static content.

    
23.09.2017 / 16:33