简体   繁体   English

关键渲染路径和第三方库

[英]Critical render path & 3rd party libraries

I am trying to follow Ilya Grigoric's performance best practices by inlining critical css & js and loading all the rest async later. 我试图通过内联关键css和js以及稍后加载所有其余异步来跟随Ilya Grigoric的性能最佳实践

My problem is when my page needs 3rd party libs in order to render its critical path. 我的问题是当我的页面需要第三方库以呈现其关键路径时。 I guess when using MVC libs like Angularjs this is not reall an option, but what if I want to use 3rd party templating library? 我想当使用像Angularjs这样的MVC库时,这不是一个选项,但是如果我想使用第三方模板库呢? Is there a small enough templating library that I can inline? 是否有一个足够小的模板库,我可以内联?

I am really trying to follow those best practices ang build a super fast mobile web-app, bit this seams to be really difficult using today's modern front-end development tools (Angularjs/Polymer etc.) 我真的想要遵循这些最佳实践,建立一个超级快速的移动网络应用程序,使用当今的现代前端开发工具(Angularjs / Polymer等),这种接缝真的很难

The question is broad and vague so it's hard to answer. 这个问题广泛而含糊,所以很难回答。

You've got a couple of issues here. 你在这里遇到了几个问题。 First, the idea of 'small enough' is relative. 首先,“足够小”的想法是相对的。 You can inline any amount of javascript, so you can technically inline any template library you find. 您可以内联任意数量的JavaScript,因此您可以在技术上内联您找到的任何模板库。

I don't know what Grigoric's specific guidance is, but if you need the template library to render anything for the user then it IS part of your critical path and should be loaded asap. 我不知道Grigoric的具体指导是什么,但如果您需要模板库为用户呈现任何内容,那么它就是您关键路径的一部分,应该尽快加载。 That said, if you're trying to create a fast experience for your user, it seems like you'd be better off rendering the html server side so the mobile device can react quicker to the response. 也就是说,如果您正在尝试为您的用户创建快速体验,那么您似乎最好不要渲染html服务器端,以便移动设备可以更快地对响应做出反应。 If your entire document is created with javascript templates on the device you're going to have to wait for the entire DOM to load, wait for the javascript to parse, and finally wait for your templates to be processed before anything is shown to the user. 如果您的整个文档是在设备上使用javascript模板创建的,那么您将不得不等待整个DOM加载,等待javascript进行解析,最后等待您的模板在向用户显示任何内容之前进行处理。

EDIT: 编辑:

Don't optimize for a performance problem until you HAVE a performance problem 在遇到性能问题之前,请不要针对性能问题进行优化

The goal is not to make the 'fastest possible page'. 目标不是制作“最快的页面”。 Instead your goal should be to make a page that 'works well'. 相反,你的目标应该是创建一个“运作良好”的页面。 Your questions don't really have 'correct' answers - it really depends on your specific situation and goals. 你的问题确实没有“正确”的答案 - 这实际上取决于你的具体情况和目标。

Regarding 'what if js is in head, will it be an issue': the answer is simply yes. 关于'如果js处于领先地位,将是一个问题':答案是肯定的。 Sure you can make tweaks to speed things up, but the basic architecture still has the same limitations - when you render templates on the client you're doing a ton more processing on the client. 当然,您可以进行调整以加快速度,但基本架构仍然具有相同的限制 - 当您在客户端上渲染模板时,您在客户端上进行了更多的处理。 Further, you have to wait significant amount of time to download resources on first request, more than you would if it were plain html coming down the line. 此外,您必须等待大量时间才能在第一次请求时下载资源,这比在纯粹的html下线时更多。

Either way, in both cases your app may function perfectly well. 无论哪种方式,在这两种情况下,您的应用程序都可以正常运行 You should just implement something and come back if you have a more specific issue. 如果你有更具体的问题,你应该实施一些东西并回来。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM