Skip to content

Commit

Permalink
Merge pull request #22 from getkirby/develop
Browse files Browse the repository at this point in the history
Version 1.0.1
  • Loading branch information
lukasbestle authored Mar 24, 2023
2 parents 9ef2d71 + 4a4c130 commit b16c5e3
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 45 deletions.
16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,13 @@ return [

If you use a custom root and/or prefix, please modify the following server configuration examples accordingly.

If your custom root is outside of the server's document root, users have been successful with these solutions:

- Create a symbolic link (symlink) from your custom root to a path inside the document root. Then use the path inside the document root in the server configuration. For this to work, the server needs to be set up to follow symlinks.
- In an Apache setup: Replace the `%{DOCUMENT_ROOT}` variable with the absolute path to your custom root on the server. E.g. `RewriteCond /var/www/yourPath/%{REQUEST_URI}/...`

In any case, please ensure that your web server has read access to the cache files in your custom root, otherwise it will not be able to handle requests with the statically cached files.

### Web server integration

This plugin will automatically generate and store the cache files, however you need to configure your web server to pick the files up and prefer them over a dynamic result from PHP.
Expand Down Expand Up @@ -228,10 +235,17 @@ To load the static cache files from PHP, please place the following code snippet
return;
}

// try to determine the content type from the static file
if ($mime = @mime_content_type($path)) {
header("Content-Type: $mime");
}

die(file_get_contents($path));
})();
```

If you want to use the PHP loader, we recommend to use it together with header support (see below). Storing the headers increases performance by a bit and also gives you more accurate responses.

### Header support

Staticache stores only the response bodies by default. The HTTP status code as well as headers set by your pages are not preserved in this mode. This ensures compatibility with all web servers.
Expand Down Expand Up @@ -268,7 +282,7 @@ Afterwards add the following block to your `.htaccess` file to make Apache use `

**PHP loader:**

Replace the last line of the loader function with this code:
Replace the last six lines of the loader function with this code:

```php
// split the file into headers (before two line breaks) and body
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"type": "kirby-plugin",
"license": "MIT",
"homepage": "https://getkirby.com/plugins/getkirby/staticache",
"version": "1.0.0",
"version": "1.0.1",
"authors": [
{
"name": "Bastian Allgeier",
Expand Down
84 changes: 43 additions & 41 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions src/StatiCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Closure;
use Kirby\Cms\App;
use Kirby\Cms\Url;
use Kirby\Filesystem\F;
use Kirby\Filesystem\Mime;
use Kirby\Toolkit\Str;
Expand Down Expand Up @@ -104,10 +105,10 @@ protected function file(string|array $key): string
}

$page = $kirby->page($key['id']);
$url = $page->url($key['language']);
$url = $page?->url($key['language']) ?? Url::to($key['id']);

// content representation paths of the home page contain the home slug
if ($page->isHomePage() === true && $key['contentType'] !== 'html') {
if ($page?->isHomePage() === true && $key['contentType'] !== 'html') {
$url .= '/' . $page->uri($key['language']);
}

Expand Down

0 comments on commit b16c5e3

Please sign in to comment.