Content:Virtual versus File Include

From Earlham CS Department
Jump to navigation Jump to search

Both include virtual and include file are examples of server side includes (SSIs). When the webserver is serving a page to a client, and it sees an include, it takes the code from the included file and "pastes" it into the file that it's serving. The only difference between the two is how you specify the path to the file.

They look something like this:

<!-- #include virtual="/includes/header.html" --> 
<!-- #include file="../../includes/header.html" -->

Include Virtual

When including a virtual, specify it from the webroot, that is, the "virtual filesystem" that the website resides on. Because of this, it is impossible to access files outside of the web document tree.

This also means that the path will be standardizes for all of the includes, which is nice for keeping the code clean. This also means that the page can be moved, and will always still find the include correctly.

Include File

When including a file, specify the path from the directory where the parent page resides.

Because it is relative to the page's position, if the parent page is moved to a different directory inside the webroot, the include's path will have to be updated by hand.