bootpress / asset
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.
Installs: 1 000
Dependents: 2
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 1
Open Issues: 0
Requires
- php: >=5.4
- bootpress/page: ^1.0
- bootpress/sqlite: ^1.0
- league/glide-symfony: ^1.0 || ^2.0
- matthiasmullie/minify: 1.3.*
- symfony/http-foundation: ^2.3 || ^3.0 || ^4.0 || ^5.0 || ^6.0 || ^7.0
- xsirix/phpuri: ^1.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^1.0
- phpunit/phpunit: ^4.0
- squizlabs/php_codesniffer: ^2.5
This package is not auto-updated.
Last update: 2024-11-28 01:27:45 UTC
README
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.
- If an asset is found we give it a unique (5 character) id that then becomes the "folder", and we add the
basename()
to the end for reference / seo sakes.- http://example.com/page/dir/bootstrap.css will become http://example.com/...../bootstrap.css where 'bootstrap.css' means nothing, and ..... is the actual asset location.
- 60 alphanumeric characters (no 0's) ^ 5 (character length) gives 777,600,000 possible combinations.
- If a #fragment is located immediately after the asset, we'll remove the fragment and ...
- If it is a .css or .js file then we will combine them together so that http://example.com/page/dir/bootstrap.css#../default.css#user/custom.css will become http://example.com/.....0.....0...../bootstrap-default-custom.css and we'll minify and serve the /page/dir/bootstrap.css, /page/default.css, and /page/dir/user/custom.css files all at once.
- Otherwise we'll replace the name with it ie. http://example.com/page/dir/image.jpg#seo will become http://example.com/...../seo.jpg
- If you add a query string to images, we'll remove and save it with the filename ie. http://example.com/page/dir/image.jpg?w=150#seo will become http://example.com/...../seo.jpg only ..... will be different from the previous example, and the image.jpg's width will be 150 pixels.
- To see all of the options here, check out the Glide Quick Reference guide.
- The
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.- This allows us to tell browsers to never come looking for the asset again, because it will never change.
- There is no better way to make your pages load any faster than this.
Installation
Add the following to your composer.json
file.
{ "require ": { "bootpress/asset": "^1.0" } }
Example Usage
<?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));
License
The MIT License (MIT). Please see License File for more information.