Content:Virtual versus File Include

From Earlham CS Department
Revision as of 11:49, 3 April 2009 by Kay (talk | contribs) (Include Virtual)
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" --> 
                     or
<!-- #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.