An open API service indexing awesome lists of open source software.

https://github.com/gioppy/statamic-aggregate-assets

Aggregate Javascript and CSS files for better performances
https://github.com/gioppy/statamic-aggregate-assets

css javascript performance statamic statamic-addon statamic-v3

Last synced: about 2 months ago
JSON representation

Aggregate Javascript and CSS files for better performances

Awesome Lists containing this project

README

          

## Aggregate assets for Statamic 3

Aggregate CSS and JavaScript files into one single file for better loading performance.

### How to use

After installing the addon, create a new disk in the `config/filesystems.php` file:

```
'aggregated' => [
'driver' => 'local',
'root' => public_path('aggregated'),
'url' => '/aggregated',
'visibility' => 'public',
]
```

You can customize the root directory according to your needs. The only constraint is that the disc visibility must be publicly visible.

To aggregate files use tags pair `{{ aggregate:css }}` and `{{ aggregate:js }}` in your `layout.antlers.html` file.

For better usage, use Aggregate in conjunction with `{{ yield }}`:

```



{{ aggregate:css }}
{{ yield:css }}
{{ /aggregate:css }}


{{ template_content }}

{{ aggregate:js }}
{{ yield:js }}
{{ /aggregate:js }}

```

In your blueprint `.antlers.html` file use as always:

```
...
{{ section:css }}

{{ /section:css }}

{{ section:js }}

{{ /section:js }}
```

Remember that the contents of the {{ aggregate }} tags will be replaced with a single CSS or JavaScript tag: insert only locally CSS and JavaScript files.

**Finally, remember that aggregation does not rewrite `url()` within CSS files.**