https://github.com/devture/silex-asset-bundle
Silex bundle that provides some simple project assets linking
https://github.com/devture/silex-asset-bundle
Last synced: 2 months ago
JSON representation
Silex bundle that provides some simple project assets linking
- Host: GitHub
- URL: https://github.com/devture/silex-asset-bundle
- Owner: devture
- License: bsd-3-clause
- Created: 2016-12-14T07:25:18.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2017-03-17T16:37:35.000Z (about 8 years ago)
- Last Synced: 2024-12-29T11:16:18.597Z (4 months ago)
- Language: PHP
- Size: 3.91 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# Asset Bundle
Provides asset linking.
## Configuration example
Example for the article bundle data source:
"AssetBundle": {
"allow_cdn": true,
"asset_path": "/srv/http/example.com/web",
"asset_url_prefix": ""
}## Initializing
$namespace = 'asset';
$app->register(new \Devture\Bundle\AssetBundle\ServicesProvider($asset, $this['config']['AssetBundle']));All provided Twig functions will be prefixed with `asset_` (the namespace used when registering).
## Usage
### Basic Asset Loading
Using the `asset_url(LOCAL_FILE)` function would generate a URL to the file.
The file will be timestamped with its last-modification-time, for caching (cache-busting) purposes.
Result:
### CDN-backed Asset Loading
Just like `asset_url(LOCAL_FILE)`, you can use `asset_url_with_cdn(LOCAL_FILE, CDN_MIRROR_URI)`
to specify a resource which is available both at the `LOCAL_FILE` path and at the `CDN_MIRROR_URI` URI.Based on the `allow_cdn` configuration parameter (passed when registering the bundle),
the appropriate URI will be used.Example:
Result (if CDN usage is allowed in the configuration):
Result (if CDN usage is NOT allowed in the configuration):
If you rely on CDN-loading, you may also with to make use of [Subresource Integrity](http://www.w3.org/TR/SRI/),
to ensure that the resource you're loading is the one you expect.Example: