6 ms·
The simplest way to create a website is just HTML and CSS, right? You can type that shit up on your desktop, post it to a server, and voilà--website! Advantages
by tomcam 11y ago
The simplest way to create a website is just HTML and CSS, right? You can type that shit up on your desktop, post it to a server, and voilà--website! Advantages: fastest possible performance and way less surface area for attacks.
Suppose you decide to add a footer to every page. If you're not a wiz at sed and command-line scripting you'll have a big chore ahead of you. Plus you might forget some pages. Plus logging into FileZilla or using SSH in order to post the files can be dreary and time-consuming.
If you're putting up a catalog or other site derived from a database, you have a whole other set of problems. Now you really want to automate. You could write this in Symfony or web2py or Django an put it on your server. If people go to yoursite.com/catalog/flashlights it's actually running a file called, say, flashlights.php that dynamically queries the database and creates HTML on the fly with a list of the flashlights category in your catalog. Advantage: it's always up to date. Disadvantage: Slower (every visit to yoursite.com/catalog/flashlights results in a database hit) and much broader attack surface.
BTW that's a little bit of a simplification. You can cache the results of the visit to yoursite.com/catalog/flashlights as an HTML file at the cost of added complexity.
A dynamic, data-driven site like that can sometimes be intercepted via evil methods such as a browser-issued SQL query or CSS injection (probably not with web2py because it's got great security, but you get my point). Dynamically generated sites, which is most of the big ones, are particularly vulnerable because of the database. Database managers are big and complex.
OK, so imagine you have a program written in Python or C or Java or whatever on your desktop. It can easily be modified to add footers or render HTML files from a database, then post the pages to your server. Advantage: pre rendered HTML files are fast and way less likely to get hacked. Disadvantage: could be less up to date. The catalog database may be updated and the rendered HTML may lag.
If you really want to get fancy you can have the program running on the server. It goes through your database and templates to create each page of the site, but instead of creating dynamic pages that run PHP or Python in order to render a web page, it creates spits out straight HTML (aka "static HTML") with the contents once a day or whatever. Now a visit to yoursite.com/catalog/flashlights actually resolves to yoursite.com/catalog/flashlights.html.
In theory static site generators are easier to understand and get started with. That's not always true, but it is true that page renders are invariably faster because it's just pure HTML and not database queries are needed.
- tedmiston 11y agoI like this answer because it gives the context around why static site generators came to be. Back in the day the simplicity of a pure html/css site was wonderful. Then as soon as we needed templating or a shared component like a footer, we bumped to to the most approachable full-blown server side language, PHP, ten years ago. Today we can use a static site generator as an alternative to fill that use case. Besides the benefits in security and performance, you can also benefit from cheaper hosting -- for example, you could host the static front end for free on GitHub Pages (even with a custom domain) or for pretty cheap on S3.