Alex
Alex

Reputation: 34978

Cache common blocks of HTML on each page

We have a common navigation bar on each page.

How would you cache this so it is not loaded on every page?

Upvotes: 1

Views: 54

Answers (2)

Sirko
Sirko

Reputation: 74046

You could load it using AJAX in the onload event of each page and append it in the respective navigation container on your page.

As long as the request to the menu stays static, the browser should be able to cache the response. Hence, you have basically cached your menu on the client's browser.

Upvotes: 1

Alex
Alex

Reputation: 34978

Put the content into a variable inside a javascript file navigation.js

nav_bar = "....."

Then include this navigation.js on each page and insert the content in the current page via JavaScript.

Upvotes: 0

Related Questions