2017 © Pedro Peláez
 

library silex-asset-bundle

Silex bundle that provides some simple project assets linking

image

devture/silex-asset-bundle

Silex bundle that provides some simple project assets linking

  • Friday, March 17, 2017
  • by spantaleev
  • Repository
  • 1 Watchers
  • 0 Stars
  • 355 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 0 % Grown

The README.md

Asset Bundle

Provides asset linking., (*1)

Configuration example

Example for the article bundle data source:, (*2)

"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)., (*3)

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., (*4)

<script type='text/javascript' src='{{ asset_url('/js/jquery.min.js') }}'></script>

Result:, (*5)

<script type='text/javascript' src='/js/jquery.min.js?1448329282'></script>

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., (*6)

Based on the allow_cdn configuration parameter (passed when registering the bundle), the appropriate URI will be used., (*7)

Example:, (*8)

<script type='text/javascript'
    src='{{ asset_url('/js/jquery.min.js', 'https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.min.js') }}'></script>

Result (if CDN usage is allowed in the configuration):, (*9)

<script type='text/javascript' src='https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.min.js'></script>

Result (if CDN usage is NOT allowed in the configuration):, (*10)

<script type='text/javascript' src='/js/jquery.min.js?1448329282'></script>

If you rely on CDN-loading, you may also with to make use of Subresource Integrity, to ensure that the resource you're loading is the one you expect., (*11)

Example:, (*12)

<script type='text/javascript'
    src='{{ asset_url('/js/jquery.min.js', 'https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.min.js') }}'
    integrity="sha384-6ePHh72Rl3hKio4HiJ841psfsRJveeS+aLoaEf3BWfS+gTF0XdAqku2ka8VddikM"
    crossorigin="anonymous"></script>

The Versions

17/03 2017

dev-master

9999999-dev

Silex bundle that provides some simple project assets linking

  Sources   Download

BSD

The Requires

 

by Slavi Pantaleev

silex bundle assets

17/03 2017

2.0

2.0.0.0

Silex bundle that provides some simple project assets linking

  Sources   Download

BSD

The Requires

 

by Slavi Pantaleev

silex bundle assets

02/01 2016

1.0

1.0.0.0

Silex bundle that provides some simple project assets linking

  Sources   Download

BSD

The Requires

 

by Slavi Pantaleev

silex bundle assets