symfony - Symfony 的 WebLink 组件:如何在 twig 中正确集成 dns_prefetch 和预连接
问题描述
我正在尝试通过集成 Symfony WebLink 组件来提高我的站点性能。
https://symfony.com/doc/current/web_link.html
我现在已经对我的 css ans js 文件使用了 preload() 函数,并且性能确实得到了提高,对此我感到非常高兴。
但是我在任何地方都找不到dns_prefetch()和preconnect( )函数如何工作的任何树枝示例。
在集成 WebLink 之前是这样的:
<link rel="dns-prefetch" href="https://www.googletagmanager.com" />
<link rel="dns-prefetch" href="https://www.googleadservices.com" />
<link rel="dns-prefetch" href="https://cdn.scarabresearch.com" />
<link rel="dns-prefetch" href="https://www.google.be" />
<link rel="dns-prefetch" href="https://www.google.co.uk" />
<link rel="dns-prefetch" href="https://gum.criteo.com" />
集成 WebLink 组件后,这就是我现在所拥有的。
{#
# Use preconnect when you are sure it will be used every time (DNS + TCP + TLS)
#}
<link rel="preconnect" href="{{ preconnect('https://www.googletagmanager.com') }}" />
<link rel="preconnect" href="{{ preconnect('https://www.googleadservices.com') }}" />
<link rel="preconnect" href="{{ preconnect('https://cdn.scarabresearch.com') }}" />
{#
# Use dns_prefetch if you are NOT sure it will be used every time (DNS lookup only)
#}
<link rel="dns-prefetch" href="{{ dns_prefetch('https://www.google.be') }}" />
<link rel="dns-prefetch" href="{{ dns_prefetch('https://www.google.co.uk') }}" />
<link rel="dns-prefetch" href="{{ dns_prefetch('https://gum.criteo.com') }}" />
所以问题很简单:
这是 Twig 中的正确表示法吗?
我不想预连接两次(如果可能的话?)
解决方案
推荐阅读
- c# - 无法使用 Azure signalR 加载类型 MessagePack
- javascript - 创建一个仅接受 0-9 的文本框,并通过为每个数字添加“1”使这些数字出现在另一个文本框中
- angular - Angular - 带有选项卡视图的启动对话框,具有简单的引导表单,不会自动聚焦到每个选项卡表单
- c# - 删除控制字符但保留 ½ 个字符等
- c# - GridSplitter 与 WindowsFormsHost 的使用。比例尺寸问题 (*)
- couchbase - Couchbase 索引建议
- php - Woocommerce API 作为客户获取产品价格
- javascript - 函数组合 - 多次遍历数组以进行多次操作不是效率低下吗?
- android - 为什么低于 5.0 的 Android 版本不易受到 CVE-2017-13156 的攻击?
- python - 仅使用特定 Csv 列的 KMeans 聚类