简体   繁体   English

PageSpeed服务/库如何帮助单页应用程序(SPA)?

[英]How does PageSpeed Service/Library helps a Single Page Application (SPA)?

I have used PageSpeed Insights and struggled with manual tricky/ad-hoc optimizations based on its results. 我使用了PageSpeed Insights,并根据结果难以进行手动的棘手/临时优化。 I am excited about using new PageSpeed Optimization Library/Service. 我对使用新的PageSpeed优化库/服务感到很兴奋。

I have a single page application( SPA ) using AngularJS. 我有一个使用AngularJS的单页面应用程序( SPA )。 Which is built using Service Oriented Architecture( SOA ). 使用面向服务的体系结构( SOA )构建的。 Have some questions, 有什么问题

  • What kind of optimizations PageSpeed Service can do for SPA ? PageSpeed服务可以为SPA做什么样的优化?
  • What pagespeed filters I should/shouldn't use ? 我应该/不应该使用哪些pagespeed过滤器?
  • [In case of PageSpeed Service ] How does AJAX requests (to my webservice) work with same-origin policy ? [在使用PageSpeed服务的情况下](对我的Web服务的)AJAX请求如何与同源策略一起使用?
  • [In case of PageSpeed Service ] Should my webservice also be running in the same google's pagespeed servers ? [如果使用PageSpeed服务 ]我的网络服务是否也应该在同一Google的pagespeed服务器中运行?

Here's some things I've learned and tried: 这是我学过并尝试过的一些东西:

1) Are you interested in changing your SPA app? 1)您是否有兴趣更改SPA应用程序?

No: 没有:

What kind of optimizations PageSpeed Service can do for SPA ? PageSpeed服务可以为SPA做什么样的优化? You'll have to read the docs. 您必须阅读文档。

What PageSpeed filters should you use? 您应该使用哪种PageSpeed过滤器? Start with the defaults. 从默认值开始。 Do black-box testing of your whole app. 对整个应用程序进行黑盒测试。 Then start to tweak the settings. 然后开始调整设置。 Measure the performance gains, so you can be aware of the rapidly diminishing returns of optimization. 衡量性能提升,这样您就可以知道优化收益迅速减少的情况。

Yes: 是:

Check out the PageSpeed extension for Chrome. 查看Chrome的PageSpeed扩展程序。 Following the suggestions will help alot. 遵循建议将有很大帮助。

You can use a build tool like grunt or gulp to transform your app's code into optimized code. 您可以使用grunt或gulp等构建工具将应用程序的代码转换为优化的代码。 It's a big topic, but here's an example for AngularJS with Gulp: 这是一个很大的话题,但这是带有Gulp的AngularJS的示例:

  // Make sources.  Uglify, Concat, and add hash if necessary
  // Determine output file.  Only used if config.concat === true
  var destJs = 'app' + (config.minify?'.min':'') + '.js';
  var appJs = gulp.src(config.app.js)
  .pipe(plugins.plumber())
  .pipe(plugins.ngAnnotate())
  .pipe(plugins.angularFilesort())
  .pipe(plugins.if(config.minify, plugins.uglify()))
  .pipe(plugins.if(config.concat, plugins.concat(destJs)))
  .pipe(plugins.if(config.hash, plugins.hash()))
  .pipe(gulp.dest(config.app.dest + '/js'))

This code: 这段代码:

  • lists all the files in config.app.js directory 列出config.app.js目录中的所有文件
  • annotates the contents with angular dependencies 用角度依赖性注释内容
  • sorts them by angular dependencies 按角度依赖性对它们进行排序
  • minifies them (if configured) 缩小它们(如果已配置)
  • concatenates them (if configured) 连接它们(如果已配置)
  • adds a filesize hash to the filename (app-4223423.js) for cache-busting (if configured) 将文件大小哈希添加到文件名(app-4223423.js)以进行缓存清除(如果已配置)
  • copies them to a folder. 将它们复制到文件夹。

Below I inject them into my index.html with this code. 在下面,我使用此代码将它们注入到我的index.html中。 See where appJs is defined above and used below: 查看上面定义appJs并在下面使用的地方:

  // Inject all these files into index.html
  return gulp.src(config.app.index)
  .pipe(plugins.plumber())
  .pipe(plugins.inject(vendorJs, _.merge({name: 'vendor'}, config.app.injectOptions)))
  .pipe(plugins.inject(vendorCss, _.merge({name: 'vendor'}, config.app.injectOptions)))
  .pipe(plugins.inject(appJs, _.merge({name: 'app'}, config.app.injectOptions)))
  .pipe(plugins.inject(appCss, _.merge({name: 'app'}, config.app.injectOptions)))
  .pipe(plugins.inject(templates, _.merge({name: 'templates'}, config.app.injectOptions)))
  .pipe(plugins.replace('REPLACE_NODE_ENV', config.NODE_ENV))
  .pipe(gulp.dest(config.app.dest))

This makes a configurable build script that can make a high performance app. 这使得可配置的构建脚本可以生成高性能的应用程序。 PageSpeed only complains about how much js I'm loading, but well, that's part of using AngularJS. PageSpeed只抱怨我正在加载多少js,但这是使用AngularJS的一部分。

[In case of PageSpeed Service] How does AJAX requests (to my webservice) work with same-origin policy ? [在使用PageSpeed服务的情况下](对我的Web服务的)AJAX请求如何与同源策略一起使用?

PageSpeed Service isn't accepting new users. PageSpeed服务不接受新用户。 There is a plugin to your webserver. 您的网络服务器上有一个插件。 So it should work the same. 因此,它应该工作相同。 Otherwise you'll probably need to enable CORS . 否则,您可能需要启用CORS

[In case of PageSpeed Service] Should my webservice also be running in the same google's pagespeed servers ? [如果使用PageSpeed服务]我的网络服务是否也应该在同一Google的pagespeed服务器中运行?

I don't know :-) You'll have to check with the service instructions. 我不知道:-)您必须检查服务说明。

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

相关问题 使用AngularJS和Sitecore(SPA)构建单页应用程序 - Building a Single Page Application with AngularJS and Sitecore (SPA) 概念说明SPA(单页应用程序) - Concept explanation SPA (Single Page Application) 使用单页应用程序(SPA)时如何在不刷新浏览器的情况下处理过期文件? - How to handle expired files without refreshing the browser when using Single Page Application (SPA)? 使用编码的UI自动执行针对角度SPA(单页应用程序)的UI测试时,单击主页上的图标不起作用 - While automating UI tests for angular SPA (Single Page Application) using Coded UI, clicking icons on home page does not work 为单页应用程序 (SPA) 创建链接以登陆不同的选项卡 - create a link for a single page application (SPA) to land on different tab 每页单服务器请求与SPA应用程序 - Single Server request per page vs SPA Application 如何删除SPA中特定页面的应用程序缓存 - how to remove the application cache for specific page in SPA 公共REST服务和AngularJS单页应用程序 - Public REST service and AngularJS single page application 如何创建不使用路由的AngularJS SPA应用程序? - How can I create an AngularJS SPA application that does not use routing? Angular JS - 非单页SPA的路径 - Angular JS - Route to Non Single Page SPA
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM