I googled this and got info about using SSI. It shows the example of

<!--#include virtual="/includes/nav.htm" -->

but when I look at existing web pages on the net, I do not see any instances of this

#include

is using SSI the way to go? Is there an example web page where I can find a working example?

thanks

Dani AI

Generated

: the reason the SSI directive does not show in the browser is that it is executed on the web server; the browser only ever sees the HTML output, so is correct. There are several practical ways to keep one navigation fragment and reuse it across pages — choice depends on hosting and workflow.

  • Server-side Includes (SSI): lightweight, handled by the web server; requires server configuration to parse files as SSI. See the Apache guide for details: Apache SSI HowTo.
  • PHP includes: very common on shared hosts — pages are parsed by PHP and a single include can insert the nav fragment. See the PHP manual: include() function.
  • Build-time/templates: static-site generators or template engines (Jekyll, Hugo, etc.) assemble pages during a build so deployed files are plain HTML and easy to host. Example: Jekyll includes.
  • Client-side injection: load a nav fragment with JavaScript (Fetch/XHR). Works, but has SEO and noscript/accessibility implications; see the Fetch API docs: Fetch API - MDN.

Troubleshooting notes: if SSI seems not to work check that mod_include (or equivalent) is enabled and the server is configured to parse the file type; for PHP verify the host actually runs PHP and files are parsed; for build tools verify the generated HTML contains the nav before deployment. For most simple shared-host sites, PHP or build-time includes give the best mix of ease and performance.

Recommended Answers

All 4 Replies

I read that SSI needs .shtml extension. I do not see many pages with .shtml extensions nowadays. Must be done some other way than SSI.

I would think this is one of the most common procedures a web page dev does (be able to update the navigation links on a multi page website).

As this is server-side (as the name suggests), you normally won't see it in the source.

Thanks for replying.

Since I know nothing about 'server side' coding, and you do not see anything in the source of the webpage, how does it work? Is server side something like a .bat file in DOS? You code something like:
- get each .html file in turn
- look for a <li> tag
- change as required

Is there a 'server side for dummies' anywhere?

Generally, you change the extension of the files you want to execute server-side code in - to be dynamic, if you will. Then your server will (hopefully) interpret or get an extension to interpret that file. The result of this will be sent to the browser.
The most widely used server-side language is PHP. There are also others, such as Perl, Ruby on Rails and Python, but these might not be installed on your server (if you're on a shared host. If not, you can install them yourself of course). There's a tutorial on php , but my way of learning it was learning something new if I needed something new.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.