heavenproject / asset-loader
Public asset files loader
Requires
- heavenproject/utils: ^1.0
- latte/latte: ^2.3
- nette/di: ^2.3
Requires (Dev)
- kdyby/tester-extras: dev-master
- mockery/mockery: ~0.9.0
- nette/application: ^2.3
- nette/bootstrap: ^2.3
- nette/tester: *
- php-mock/php-mock-mockery: ~1.1.0
This package is not auto-updated.
Last update: 2024-11-10 01:26:03 UTC
README
Public asset files loader.
Installation
composer require heavenproject/asset-loader
How It Works
Asset Loader is Latte macro.
After the asset file is loaded in the Asset Loader, it reads the asset url,
saves this information in temporary file and appends a version number
after this url in a form of query string,
e.g. http://example.com/images/image.jpg?v=1
. After the asset file has been
modified, Asset Loader registers this during a new request and increases
version number in url query string,
e.g. http://example.com/images/image.jpg?v=2
. This will force the web browser
to download a new version of this asset file from server instead of using
it from browser cache.
NOTE: Asset files can be loaded either just by specifiyng its absolute filepath from the website document root directory, e.g.
/images/image.jpg
or by using its external url, e.g.http://example.com/images/image.jpg
, but if using the later form (external url), keep in mind, that trying to work with assets from different domains will not work, because in this case Asset Loader checks the domain in url and if it does not match the website url, it will only return the original url that was given to it, so browser can work with the given resource as usual. So please only load your website local assets.
Requirements
Documentation
In order to use Asset Loader you must register it as extension in configuration file:
extensions: asset: HeavenProject\AssetLoader\AssetLoaderExtension
Then you must configure it:
asset: publicDir: %wwwDir% targetDir: %tempDir%/assets
After this you are ready to use the Asset Loader:
<img src="{asset $basePath . '/images/image.jpg'}" alt="Image">
License
This source code is free software available under the MIT license.