Skip to content
This repository was archived by the owner on Oct 13, 2025. It is now read-only.

Commit dd0c101

Browse files
TcFxGt4AGEhailwood
authored andcommitted
Added ability for CDN assets (#6)
* Added ability for CDN assets * Update README.md
1 parent 5189132 commit dd0c101

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,13 @@ class Page extends SiteTree {
6363
## Relative Assets Extension
6464
- Prefixes all references to `assets/*` with a preceeding slash i.e. they become something like `/assets/some.png`
6565
- If [zaininnari/html-minifier](https://github.com/zaininnari/html-minifier) is installed minifies the HTML output before rendering.
66+
- If Assets.host config is set then Assets will be prefixed with this host.
67+
68+
```yaml
69+
Assets:
70+
host: '//example.com/'
71+
```
72+
Would equal `//example.com/assets/image.png`
6673

6774
## FooterMenuExtension
6875
- Adds a new *ShowInFooter* option to the page settings

code/SS_RelativeAssetsResponse.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,10 @@ public function setBody($body)
2222
{
2323
$body = (string)$body;
2424

25+
$prefix = Config::inst()->get('Assets', 'host') ?: '/';
26+
2527
$body = str_replace('"/assets/', '"assets/', $body);
26-
$body = str_replace('"assets/', '"/assets/', $body);
28+
$body = str_replace('"assets/', sprintf('"%sassets/', $prefix), $body);
2729

2830
if (!json_decode($body) && class_exists('zz\Html\HTMLMinify')) {
2931
$this->body = zz\Html\HTMLMinify::minify($body, [

0 commit comments

Comments
 (0)