devture/silex-asset-bundle 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

devture/silex-asset-bundle

Composer 安装命令:

composer require devture/silex-asset-bundle

包简介

Silex bundle that provides some simple project assets linking

README 文档

README

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.

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

Result:

<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.

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

Example:

<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):

<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):

<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.

Example:

<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>

统计信息

  • 总下载量: 370
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: BSD
  • 更新时间: 2016-12-14

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固