Skip to content

Commit b16c5e3

Browse files
authored
Merge pull request #22 from getkirby/develop
Version 1.0.1
2 parents 9ef2d71 + 4a4c130 commit b16c5e3

File tree

4 files changed

+62
-45
lines changed

4 files changed

+62
-45
lines changed

README.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,13 @@ return [
150150

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

153+
If your custom root is outside of the server's document root, users have been successful with these solutions:
154+
155+
- 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.
156+
- 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}/...`
157+
158+
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.
159+
153160
### Web server integration
154161

155162
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.
@@ -228,10 +235,17 @@ To load the static cache files from PHP, please place the following code snippet
228235
return;
229236
}
230237

238+
// try to determine the content type from the static file
239+
if ($mime = @mime_content_type($path)) {
240+
header("Content-Type: $mime");
241+
}
242+
231243
die(file_get_contents($path));
232244
})();
233245
```
234246

247+
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.
248+
235249
### Header support
236250

237251
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.
@@ -268,7 +282,7 @@ Afterwards add the following block to your `.htaccess` file to make Apache use `
268282

269283
**PHP loader:**
270284

271-
Replace the last line of the loader function with this code:
285+
Replace the last six lines of the loader function with this code:
272286

273287
```php
274288
// split the file into headers (before two line breaks) and body

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"type": "kirby-plugin",
55
"license": "MIT",
66
"homepage": "https://getkirby.com/plugins/getkirby/staticache",
7-
"version": "1.0.0",
7+
"version": "1.0.1",
88
"authors": [
99
{
1010
"name": "Bastian Allgeier",

composer.lock

Lines changed: 43 additions & 41 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/StatiCache.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Closure;
66
use Kirby\Cms\App;
7+
use Kirby\Cms\Url;
78
use Kirby\Filesystem\F;
89
use Kirby\Filesystem\Mime;
910
use Kirby\Toolkit\Str;
@@ -104,10 +105,10 @@ protected function file(string|array $key): string
104105
}
105106

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

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

0 commit comments

Comments
 (0)