如何使用元标记在manifest.json文件中添加Urls和web_Urls [英] how to add Urls and web_Urls in manifest.json file using meta Tag

查看:155
本文介绍了如何使用元标记在manifest.json文件中添加Urls和web_Urls的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个渐进式Web应用程序,我需要使用元标记在manifest.json文件中添加当前URL。

I am creating a progressive web app, and I need to add current URL in manifest.json file using meta tag.

我创建了这个manifest.json:

I created this 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&网址,但我希望将其作为动态网址(EX:www.example.com/< PRODUCT_ID>)

the above JSON is working fine in static URL & web URL, but I want to get it working for as a dynamic URL (EX:www.example.com/< PRODUCT_ID > )

推荐答案

JSON不遵守 Web App Manifest规范,这是当前使用的规范在将Web应用程序添加到设备的主屏幕时,通过Chrome和Firefox获取metdata。具体来说,您需要使用 start_url property 指定要打开的初始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 基于某事的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 值,然后设置< link rel =manifest> 每个页面上的标记指向相应的 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆