如何使用元标记在 manifest.json 文件中添加 Urls 和 web_Urls [英] how to add Urls and web_Urls in manifest.json file using meta Tag
问题描述
我正在创建一个渐进式网络应用程序,我需要使用元标记在 manifest.json
文件中添加当前 URL.
I am creating a progressive web app, and I need to add the current URL in manifest.json
file using meta tag.
我创建了这个 manifest.json
:
{
"name": "app",
"icons": [{
"src": "images/avatar.jpg",
"sizes": "64x64"
}, {
"src": "images/avatar.jpg",
"sizes": "64x64"
}, {
"src": "images/avatar.jpg",
"sizes": "128x128",
"density": 2
}],
"app": {
"urls": [
"https://www.example.com"
],
"launch": {
"web_url": "https://www.example.com"
}
}
"theme_color":"#06ADD5",
"display": "standalone",
"orientation": "portrait"
}
上面的 JSON 在静态 URL 和 Web URL 中工作正常,但我想让它作为动态 URL 工作(例如:www.example.com/
)
The above JSON is working fine in static URL and web URL, but I want to get it working for as a dynamic URL (EX:www.example.com/<PRODUCT_ID>
)
推荐答案
该 JSON 不符合 Web 应用程序清单规范,这是 Chrome 和 Firefox 当前在将网络应用程序添加到设备主屏幕时用于元数据的规范.具体来说,您需要使用 start_url
属性指定要打开的初始 URL.
That JSON does not adhere to the Web App Manifest specification, which is what's currently used by Chrome and Firefox for metdata when adding a web app to a device's homescreen. Specifically, you'd want to use the start_url
property to specify the initial URL to open.
无论如何,根据某些标准自定义 /path/to/manifest.json
的内容的问题归结为您通常如何对任何资源进行服务器端自定义在将其返回给客户之前.你可以传入一个 URL 参数,比如 /path/to/manifest.json?start_url=*something*
,然后让你的 web 服务器返回一个不同的 start_url
值基于 something 是什么的 JSON 响应.
In any case, the question of customizing the contents of /path/to/manifest.json
based on some criteria just boils down to how you'd normally do server-side customization of any resource before returning it to the client. You could pass in a URL parameter, like /path/to/manifest.json?start_url=*something*
, and then have your web server return a different start_url
value in the JSON response based on what something is.
如果你不能实现服务器端逻辑,也许是因为你只部署静态文件并且对所有东西都使用客户端渲染,那么你最好的办法是生成多个 manifest-*something*.json
文件,每个文件都有不同的 start_url
值,然后将每个页面上的 标签设置为指向到适当的
manifest-*something*.json
URL,基于对您有意义的任何标准.
If you can't implement server-side logic, perhaps because you're only deploying static files and using client-side rendering for everything, then your best bet is to generate multiple manifest-*something*.json
files ahead of time, each with a different start_url
value, and then set the <link rel="manifest">
tag on each page to point to the appropriate manifest-*something*.json
URL, based on whatever criteria makes sense for you.
这篇关于如何使用元标记在 manifest.json 文件中添加 Urls 和 web_Urls的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!