weixin_39917576
weixin_39917576
2020-11-29 04:13

Try out the Content Indexing API

The Content Indexing API is running as an Origin Trial in Chrome 80.

Since all web.dev posts under /blog/ that a user has visited are cached and should work offline, web.dev should consider trying out the Content Indexing API.

Using the API when you already have an offline-capable PWA is pretty straightforward. Here are some examples of adding it to some PWAs that I maintain. If you're open to the idea but there's no engineering time from the core team available, I could submit a PR to add support.

CC:

该提问来源于开源项目:GoogleChrome/web.dev

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

14条回答

  • weixin_39917576 weixin_39917576 5月前

    Cool! This is what I came up with as a first cut: https://github.com/GoogleChrome/web.dev/compare/content-indexing-support

    It definitely needs some more work, and I'd love to chat with the eng team about how page loading and your service worker caching setup works to ensure that I'm making the right decisions.

    On Chrome 80+ for Android, you'd end up seeing something like this after browsing around a bit:

    Screenshot (Dec 20, 2019 2_07_13 PM)

    点赞 评论 复制链接分享
  • weixin_39875842 weixin_39875842 5月前

    This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. To prevent his from happening, leave a comment.

    点赞 评论 复制链接分享
  • weixin_39917576 weixin_39917576 5月前

    So I would still like to do this, especially now that the SW caching stuff seems more settled.

    I can revise my original code into something more production-y.

    点赞 评论 复制链接分享
  • weixin_39844549 weixin_39844549 5月前

    Thanks . if we move ahead with this would you feel comfortable maintaining it? Should we have sw tests in place before we add it so we can ensure we don't break it?

    点赞 评论 复制链接分享
  • weixin_39917576 weixin_39917576 5月前

    I speculatively refactored the service worker partial JSON output, so that it includes extra description, url, and imageSrc fields, when those values are available. This should be backwards compatible with the existing cache storage entries, so I didn't bump the versioning in the cache name.

    That makes using the Content Indexing API a lot easier, as I can just do a sweep through all of the indexed JSON once inside of bootstrap.js, and use the values directly from cache storage to keep the index up to date. Otherwise, I had to put some code inside of loader.js that would react to every page load and pull out the required metadata, using CSS class names to figure out the description and/or imageSrc values, and that was messy.

    Let me know what you think about that approach by taking a look at https://github.com/GoogleChrome/web.dev/compare/content-indexing-support

    (I think the new git hook that bumps the updated field in the Markdown source files is too aggressive, as each time I do a npm run build locally, new Markdown files with updated dates end up being committed.)

    点赞 评论 复制链接分享
  • weixin_39844549 weixin_39844549 5月前

    hm I don't think the hook should be triggered on build, it should run when commit gets called. If you do git commit --no-verify it will not run.

    点赞 评论 复制链接分享
  • weixin_39844549 weixin_39844549 5月前

    would you be ok with opening a PR so we can review? Might be easier to do it that way so we can comment on lines versus doing the branch diff

    点赞 评论 复制链接分享
  • weixin_39917576 weixin_39917576 5月前

    Sure. Let me create a clean branch and I'll file a PR.

    点赞 评论 复制链接分享
  • weixin_39917576 weixin_39917576 5月前

    I filed https://github.com/GoogleChrome/web.dev/pull/2798

    点赞 评论 复制链接分享
  • weixin_39875842 weixin_39875842 5月前

    This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. To prevent his from happening, leave a comment.

    点赞 评论 复制链接分享
  • weixin_39917576 weixin_39917576 5月前

    2798 is still waiting on feedback from .

    点赞 评论 复制链接分享
  • weixin_39875842 weixin_39875842 5月前

    This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. To prevent this from happening, leave a comment.

    点赞 评论 复制链接分享
  • weixin_39875842 weixin_39875842 5月前

    This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. To prevent this from happening, leave a comment.

    点赞 评论 复制链接分享
  • weixin_39844549 weixin_39844549 5月前

    If you have the bandwidth to submit a PR I know we'd appreciate it. It sounds like a rad feature but wasn't something we had immediate plans to work on.

    点赞 评论 复制链接分享

相关推荐