If you've arrived at this page, you've probably been doing one of three or things:
- You might have been looking for pages that link to your website.
The first of those three options is probably the most common, and we'll talk about that at length in a moment.
What are includes? And why should we use them?
An include is a section of a web page that draws its content from another source. The idea is simple: if several pages will use the same content, that content can be stored in a single location. Each page using that content will grab it directly from the file.
As an example, suppose that we want to include a copyright notice at the bottom of every page in a website. When the new year rolls around, we want to update that copyright notice. If we inserted the date on every individual page, we'd have a truckload of changes to make; but if we keep the copyright notice in an include file, we'd need to change only that one file to have the update appear on every page.
Include files are usually handled "server-side." With a server-side include, the webserver handles the task of extracting the contents of the include and inserting it into other pages.
Unfortunately, there are some down sides to this method. First, different webservers use different file suffixes for includes. That means that if you're using a Microsoft IIS webserver, you'll probably be using .asp or .aspx files. If you are using Apache, you'll probably be using .shtml or .html files. That means that if you want to port your site to a different server platform, you're going to have to change page names... and that will likely also mean that you'll have to change all the links within those pages, too. Not a pretty prospect.
There is one other annoying aspect to relying on server-side includes. If you want to preview your pages locally, you'll need to have a compatible webserver running on your development machine. After all, server-side includes don't work when there isn't a server.
Alternatively, you can rely on "client-side" includes. With a client-side include, the web browser is reponsible for managing the process of getting the data out of the include file and inserting it into the webpage.
Here's an example of what I use on this site. First, a script tag like that below is inserted into the appropriate location in the page:
Then, in the "linklist.js" file, you'd have this:
Another drawback is that search engines will not index text within scripts. For that reason, you should avoid putting critical content in the scripts.