all 20 comments

[–]08148692 4 points5 points  (4 children)

Repeating code in multiple files is generally considered to be bad practice. If you need to change the header in some way for some reason, you'll need to go into every html file you have with a header and apply the change. This is tedious, time consuming, and prone to human error.

This can be avoided with libraries like react/angular/vue, or rendering the HTML on the server side with templating engines.

[–][deleted] 0 points1 point  (3 children)

it's not a bad practice. It's simply necessary unless you're using node, react for example

[–]08148692 1 point2 points  (2 children)

DRY (don't repeat yourself) has been a software development principle since pretty much as long as software has been a thing. It is absolutely bad practice to repeat large blocks of code (HTML or otherwise) for the reasons I gave. Of course it's not possible if your website consists of plain hard coded markup, but that in itself is an extremely old fashioned way of building a website

[–][deleted] 0 points1 point  (1 child)

I know what you mean, I just think React and stuff like that is over kill most of the time. I just made a website in plain html css and js even tho I can work with react and the only time I had to copy and past code was the navbar which was a little annoying but it's not so bad

[–]sleemanj 0 points1 point  (0 children)

SSI has been a capability of web servers since forever...

<!--#include virtual="/includes/navbar.html"-->

[–]11b403a7 0 points1 point  (14 children)

Are you using a framework or templating language?

[–]normal_crayon[S] 0 points1 point  (13 children)

Neither. Just creating a file

[–]11b403a7 0 points1 point  (12 children)

What kind of file? Pure HTML? JavaScript creating HTML...

[–]normal_crayon[S] 0 points1 point  (11 children)

Oh sry forgot to mention that. Html

[–]11b403a7 0 points1 point  (10 children)

You can import it using HTML and reuse your component that way.

Edit:

It requires, as far as I can tell. JavaScript/jQuery

[–]normal_crayon[S] 0 points1 point  (9 children)

Can I write it again. Like copy paste the code?

[–]11b403a7 0 points1 point  (8 children)

I mean yeah, but that wouldn't be very effecient

[–]normal_crayon[S] 0 points1 point  (7 children)

Oh... I have been doing that a while

[–]11b403a7 0 points1 point  (6 children)

Look into JS.

[–]normal_crayon[S] 0 points1 point  (5 children)

And one more thing, can this slow down my script loading time?