Platform.sh User Documentation

Server Side Includes (SSI)

Sign up for Upsun

Get your free trial by clicking the link below.

Get your Upsun free trial

SSI commands enable you to include files within other pages.

At its most basic, you can include files within other ones so as not to repeat yourself.

Start by enabling SSI:

.platform/routes.yaml
"https://{default}/":
    type: upstream
    upstream: "app:http"
    ssi:
        enabled: true

Then create a file you want to include elsewhere:

includes/example.html
<p>This content can be reused</p>

And include it in another file:

index.html
<body>
  <p>This content is unique to this page.</p>
  <!--#include virtual="includes/example.html" -->
</body>

And your final rendered page includes the other file:

index.html
<body>
  <p>This content is unique to this page.</p>
  <p>This content can be reused</p>
</body>

Caching and dynamic content Anchor to this heading

You can use SSI to have caching and dynamic content in one. So one file is cached, while another updates dynamically.

For example, you can activate SSI on one route with cache disabled and enable cache on another route:

.platform/routes.yaml
"https://{default}/":
    type: upstream
    upstream: "app:http"
    ssi:
        enabled: true
    cache:
        enabled: false

"https://{default}/cache":
    type: upstream
    upstream: "app:http"
    cache:
        enabled: true

Then create a page that displays the current date and time and is cached for 60 seconds (the example uses PHP, but any server-side language would work):

cache/example.php
<?php
header("Cache-Control: max-age=60");
echo date(DATE_RFC2822);

Then you could have a page with dynamic content that includes this file:

index.php
<?php
echo date(DATE_RFC2822);
?>
<!--#include virtual="cache/example.php" -->

Then you can visit index.php and refresh the page a few times. You see the first number updating to the current time, while the second (included) one only changes every 60 seconds.

For more on SSI, see the nginx documentation.

Is this page helpful?