How to repeat content on multiple static pages?

Asked

Viewed 267 times

3

The point is, I have only static files. HTML and am looking for a simple way to create the blocks just once using only the client side.

The idea is to respect DRY, there is some way to do this directly with Javascript or jQuery?

  • Why not use the.js code and import it on the pages?

  • @Miguel, can you give me a simple example of how Voce would matter?

  • <script src="path/to/o/teu/codigo.js"></script>, at the bottom of html, before closing the tag <body></body>

1 answer

5


Yes, it is possible.

Using the load() jQuery

Example: load the contents of header.html for the div with id header.

$("#header").load("public/header.html");
  • can tell me the question of performance, if it influences much?

  • 1

    It will depend on some factors, possibly carrying everything direct is (minimally) more performatic, at least in normal situations and also, almost always this performance gain is imperceptible. I can assure you that I gain in performance in do not use this type of feature does not compensate for the loss of time and the headache it will be having to edit many files every time it will need a change, even more so if the site has many pages. You need to evaluate a satisfactory way, even if I knew to answer you with certainty what the most performatic, you [+]

  • [+] will need to evaluate the case before its scope. (PS: Tou leaving now. Any doubt, leave a comment there that when I return I reply)

  • Just by complementing, you can either set the loading of entire pages or just a specific block, e.g. a div, a table etc.: $("#nome-da-div").load("public/header.html #nome-da-div");.

Browser other questions tagged

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