Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Q&A

Welcome to Software Development on Codidact!

Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.

Post History

60%
+1 −0
Q&A Reusing HTML without rewriting it

I agree with other answers that a static site generator is the best approach. This is something that the original designers of HTML left as an open problem. The problem has now been "solved" by thi...

posted 4mo ago by matthewsnyder‭

Answer
#1: Initial revision by user avatar matthewsnyder‭ · 2024-08-13T16:11:48Z (4 months ago)
I agree with other answers that a static site generator is the best approach. This is something that the original designers of HTML left as an open problem. The problem has now been "solved" by third party tools, and there's not yet a good alternative to HTML. Static site generators are those tools.

HTML does not support includes, so indeed in vanilla HTML you are expected to duplicate the content on each page.

In theory, you can make the common content a separate page, and display it in a frame. This would have several drawbacks, one of them being that you can't have the footer be slightly different on each page (like highlighting the current page).

You could author your documents in some other format (that supports includes), and then compile them. Python's Jinja library can do this, as can Pandoc, and many others. However, you would be reinventing the wheel, since static site generators are already a mature implementation of this idea.

These days many sites generate the HTML both client and server side. The server (for example, Python Flask) can calculate each part of the page dynamically when serving each visitor, then compose them together. On the client side, Javascript can further modify the HTML. Sometimes the server just sends over data packets (like JSON) instead of HTML, and it gets rendered into HTML by client side JS. This is a popular approach in commercial frontends, but likely not worth the effort for you unless you want to make a webapp.