From the Matrix movie.
"There is no spoon."*

Virtual Includes

When building a website using Bootstrap and HTML, one can use "virtual includes" to call small files containing standard items such as navigation bars, copyright notices, banner ad display areas and suchlike items -- things that will be identical from page to page on every page of a website. Virtual includes will lessen the amount of time you spend cutting and pasting (and revising) those standard "boilerplate" items that are on every page of a site. The "virtual include" command works like this:

<html>
<head>
</head>
<body>
<!--#include virtual="header.html" -->
<!--#include virtual="navbar.html" -->

Text of the page goes here

More content, content, content, etc.

<!--#include virtual="footer.html" -->

</body>
</html>

For this to work on a UNIX server and have it routinely parse your pages for commands to execute when serving up html, you either need to name your files with an .shtml extension like this: "sample-file.shtml" (the .shtml extension tells the server to parse for and execute things like the include commands)

OR

if it is going to be a lot of trouble to name or rename all the files of the website so they have .shtml extensions instead of .html extensions, there is a way to have the server parse your .html files for includes without having to rename them as .shtml files.

Create (or modify, if it already exists) the file named ".htaccess" in your root directory and insert into it this line:

AddType text/x-server-parsed-html html

The great thing about virtual includes is that you can make just one change to your copyright notice, or to your navigation bar, and it will show up on all the pages where it is included. If you're doing a big website with hundreds or thousands of pages with identical content in the navigation bar, copyright notice, newsletter subscription box, and so on, these virtual includes can save you a lot of time if you ever have to revise these things. Make the change to the included file and viola! you're done across the entire site.

When NOT to use virtual includes:

1) When the navigation bar is different on every page.

2) Virtual includes make the server work harder to serve up the same information. If your server is already overtaxed virtual includes may not be a good idea as they may slow down the presentation of the information to your visitors. When in doubt, check with your web hosting provider or system administrator, or run a test and see for yourself.

We rarely use virtual includes nowadays—instead we use php to build most of our websites in 2024. Even this page you are viewing, virtual-includes.html, is served up using php to build it from pieces. There is no actual file by that name. It just seems like there is. The pieces of it (header, navigation bar, footer) are all called from pieces.

*This is a reference to the first Matrix movie, where one of the characters says "There is no spoon," about the spoon he is bending around with his mind.



25 years of online marketing

Celebrating 25 Years of Creating an Island of
Stability In the Sea of Online Confusion

Copyright © 1997-2024 Words in a Row - All Rights Reserved.