Symfony之components--第二章--第一讲:assert组件的使用

news/2024/5/20 0:52:06 标签: Symfony
Assert Component
assert component manages url generation and versioning of web asset such as
css, js and images.
in the past, it was common for web applications to hardcode urls of web assets(资源).
for example:
<link rel="stylesheet" type="text/css" href="/css/main.css">
缺点:
模板冗余
版本控制困难
移动资源的位置是非常繁琐而且极其容易出错
加载多个cdn几乎不可能


Usage
Asset Packages
Versioned Assets
one of the main features of assert component is the ability to manage the versioning
of the application's assets.Asset versions are commonly used to control how these
assets are cached.不是依赖于简单的版本机制,asset component允许你定义先进的版本控制策略.
这两个机制是EmptyVersionStrategy,不添加任何版本到资源,StaticVersionStrategy,允许你用格式的字符串
设置一个版本.
use Symfony\Component\Asset\Package;
use Symfony\Component\Asset\VersionStrategy\EmptyVersionStrategy;


$package = new Package(new EmptyVersionStrategy());


echo $package->getUrl('/image.png');
// result: /image.png


use Symfony\Component\Asset\Package;
use Symfony\Component\Asset\VersionStrategy\StaticVersionStrategy;


$package = new Package(new StaticVersionStrategy('v1'));


echo $package->getUrl('/image.png');
// result: /image.png?v1


// put the 'version' word before the version value
$package = new Package(new StaticVersionStrategy('v1', '%s?version=%s'));


echo $package->getUrl('/image.png');
// result: /image.png?version=v1


// put the asset version before its path
$package = new Package(new StaticVersionStrategy('v1', '%2$s/%1$s'));


echo $package->getUrl('/image.png');
// result: /v1/image.png

http://www.niftyadmin.cn/n/861207.html

相关文章

TCP 与UDP 区别

1.tcp:面向连接 udp:无连接 2.tcp:大包 --> 小包 不丢包 序列化 可靠 udp&#xff1a;面向直播&#xff0c;实时传输&#xff0c;所以传播中丢了一些包也没有关系&#xff0c;不太可靠 3.tcp:面向字节流 udp:面向报文 3.tcp: 一对一 udp:一对一或一对多 4.tcp 首部&…

Symfony之components--第二章--第二讲:BrowserKit组件的使用

BrowserKit Componentsimulates(模拟)一个网络浏览器的习惯&#xff0c;允许你发送请求&#xff0c;点击链接和表单提交&#xff0e;Basic Usage创建一个客户该组建只提供哦你一个抽象的客户段&#xff0c;并且不提供任何后台http层的任何操作&#xff0e;创建自己的client&…

js 语言

1.html 与js 这两种语言区别 html 是标记语言&#xff0c;她的语言组成是标签&#xff0c;eg:<head></head> js:编程语言 因为他有数据保存 运算 逻辑判断 循环 而编程语言&#xff1a;机器语言&#xff08;0 和1二进制&#xff09; 汇编语言 高级语言 2.编程…

Symfony之components--第二章--第三讲:cache组件的使用

cache组件为添加cache到应用中提供了一个严格的psr-6实现&#xff0e;低开销以及即将为最流行的后台缓存使用适配器&#xff0e;key concepts(概念)Before starting to use the cache component, its important that you learn the meaning ofsome key concepts:item一个信息存…

浏览器组成和内核引擎(渲染引擎和js 引擎)

浏览器&#xff1a; 可见&#xff1a;shell 可操作页面 不可见&#xff1a;内核&#xff1a;渲染引擎 后来分出来的js 引擎 浏览器内核&#xff1a; 浏览器渲染引擎js 引擎chrome (谷歌)webkit --> blinkv8(这个引擎厉害&#xff0c;记住这个即可)firefox&#xff08;火…

一个laravel文件中创建多个应用

服务器采用nginx在nginx下配置路径首先会找到laravel文件中的public下的index.php这里重新创建一个admin&#xff08;和public在同一个目录&#xff09;文件&#xff0c;nginx配置路径到admin下的index.php文件&#xff0c;开始模拟在laravel中的另一个应用将public下的所有文件…

csrf学习笔记

cross-site request forgery跨站点请求伪造它是一个攻击&#xff0c;让受害者提交恶意的请求&#xff0e;对于大多数网站来说&#xff0c;浏览器自动请求都包含了一些证书&#xff0c;例如用户的session cookie, ip地址&#xff0c;Windows域凭据等&#xff0c;因此&#xff0c…

提高网站运行速度的一些策略

学习网址&#xff1a;https://developer.yahoo.com/performance/rules.html#page-nav大多用户的等待时间花费在前台&#xff0c;图片&#xff0c;样式&#xff0c;脚本&#xff0c;动画等的加载话费了大量的时间&#xff0c;那么如何让网站即拥有丰富的页面内容&#xff0c;有可…