Caches and delivers assets of every sort, from any location, with hands-off versioning. Manipulates images on-the-fly. Minifies and combines (on-demand) css and javascript files.
Check if the current page is a cached asset you need to $page->send()
.
The folder you want to cache all your assets in.
Optional parameters to use when setting up the Glide Server Factory. The only ones we'll use are:
Either false
or a Symfony\Component\HttpFoundation\Response for you to send.
use BootPress\Page\Component as Page;
use BootPress\Asset\Component as Asset;
$page = Page::html();
if ($asset = Asset::cached('assets')) {
$page->send($asset);
}
Finds all the assets in your $html, and caches them.
You only need to use this if you are not $page->display()
ing the html you want to send.
The $html with all of your asset links cached.
$json = array('<p>Content</p>');
$page->sendJson(Asset::urls($json));
Prepares a Symfony Response for you to send.
Either a file location, or the type of file you are sending eg. html, txt, less, scss, json, xml, rdf, rss, atom, js, css
The string of data you want to send, or an array of options if $file
is a location. The available options are:
If you are sending the content directly and want to cache it, then you can make this an array($content, 'expires' => ...)
.
A Symfony\Component\HttpFoundation\Response for you to send.
$html = $page->display('<p>Content</p>');
$page->send(Asset::dispatch('html', $html));
Get the mime type(s) associated with a file extension.
If this is a string then we'll give you the main mime type (for sending). If it's an array then we'll give you all of the mime types (for verifying).
The mime type(s).
echo Asset::mime('html'); // text/html
echo implode(', ', Asset::mime(array('html'))); // text/html, application/xhtml+xml, text/plain
Asset::cached()
is a one-stop method for all of your asset caching needs. This should be the first thing that you call. It checks to see if the page is looking for a cached asset. If it is, then it will return a response that you can $page->send()
. If not, then just continue on your merry way. When you $page->display()
your html, it will look for all of your assets, and convert them to cached urls.
basename()
to the end for reference / seo sakes.
filemtime()
is saved so that when an asset changes, we can give it a new unique filename that the browser will then come looking for and cache all over again.
Add the following to your composer.json
file.
{
"require ": {
"bootpress/asset": "^1.0"
}
}
<?php
use BootPress\Page\Component as Page;
use BootPress\Asset\Component as Asset;
$page = Page::html();
if ($asset = Asset::cached('assets')) {
$page->send($asset);
}
$html = $page->display('<p>Content</p>');
$page->send(Asset::dispatch('html', $html));