在移动网站上生产服务工作者 [英] Inroducing service-workers on mobile site

查看:85
本文介绍了在移动网站上生产服务工作者的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是服务人员的新手。我想整合服务人员在我的网站。我的动机是提高我的网站的性能,而不是让网站离线。它是一个房地产网站。

直到现在我已经完成了创建我的站点的模块化模板并将它们存储在缓存中。例如
template1

 < div> 
< p>#data< / p>
< div>

无论何时在我的页面上发生抓取时,我首先通过ajax调用api获取数据并替换#数据变量通过实际的api响应缓存响应,然后我将新的响应返回给浏览器。



问题1: - 要知道的是正确的做法。为html模板缓存吗?



在上面的方法中,我在我的html中收到类似循环和条件语句的挑战。
问题2: - 是否有任何方法可以缓存具有循环的模板并在运行时更改它们?

问题3: - 说,如果我最初向用户展示缓存的应用程序外壳,那么是否会影响我网站的搜索引擎优化排名?



<问题4: - 我必须编写新的现有代码模板,这意味着我必须为服务工作人员和其他不支持服务人员的普通浏览器维护两个代码。任何解决方案

这是很多问题,我不认为服务人员一定是你最好的选择。



问题1:我个人建议使用一个框架,如KnockoutJS,Angular,聚合物...等你的HTML模板。这些通常有内置的模板缓存。



问题2:而不是您使用的方法,即在发送之前替换变量他们对浏览器的大多数框架都会使用某种形式的数据绑定,这些绑定会处理浏览器中的迭代和条件。



问题3:缓存app-shell对SEO没有任何影响,Google一直在解析JavaScript;然而,个人我建议网站的内容无JavaScript加载,然后JavaScript仅用于增强体验。无论是否使用app-shell模型,这都是一样的。



问题4:我不了解您当前的设置,不是一个普通的场景,所以你可能有什么问题。

服务工作者和缓存API通常用于缓存你的静态资产,通常是字体,CSS,JavaScript和HTML模板,并且由于HTTP请求较少,因此应该可以提高性能;但还有其他方法可以提高性能,而无需使用服务人员即可解决所有问题。


I'm new to service workers. I want to integrate service workers in my site.My motive is to improve the performance of my website not making the website offline.Its a real estate website.

So what i have done till now is create modular templates of my site and store them in the cache. for e.g. template1

<div>
     <p>#data</p>
<div>

whenever a fetch occurs on my page i first call an api through ajax get the data and replace the #data variable in the cache response by actual api response and then i returned the new response to the browser.

Question 1:- So i want to know is that the right approach. for html template caching?

In the above approach i'm getting challenges like loops and conditional statements in my html. Question 2:- Is there any way that i can cache the templates with loops and change them at run time?.

Question 3:- Say if i show the cached app-shell to the user initially, so is that going to effect my site's SEO ranking?.

Question 4:- I have to write new templates of the existing code, which means i have to maintain two codes one for service-workers and other for normal browsers which dont support service workers.Any solution to this?

Regards

解决方案

That's a lot of questions and I don't think service workers are necessarily your best bet.

Question 1: Personally I recommend using a framework such as KnockoutJS, Angular, Polymer...etc for your HTML templates. These often have template caching built-in.

Question 2: Instead of the approach you are using whereby you are replacing the variables before 'sending them to the browser' most frameworks would use some form of data bindings which would take care of iterations and conditions within the browser.

Question 3: Caching the app-shell would have no effect on SEO and Google has been parsing JavaScript for a while; however personally I would recommend that the website's content loads without JavaScript and then JavaScript is only used to enhance the experience. This would be the same whether using the app-shell model or not.

Question 4: I do not understand your current setup and this would not be an ordinary scenario so you might have something wrong.

Service workers and the Cache API are ordinarily used to cache your static assets, usually fonts, css, JavaScript and HTML templates and should result in improved performance as there are less HTTP requests; but there are other ways to improve performance that will address all of your questions without the use of service workers.

这篇关于在移动网站上生产服务工作者的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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