检测到单页的应用程序应用程序版本变化 [英] Detect application version change on a single page application

查看:117
本文介绍了检测到单页的应用程序应用程序版本变化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

今天的问题在这里提出和我没有一个明显的答案。

today a question was raised here and I don't have an evident answer.

假设我们串接和缩小的所有资源文件(CSS和Javascript),并在母版页申报。

Assume that we concatenate and minify all resource files (CSS and Javascript) and declare them in the "Master-Page".

在一个多页的应用程序,如果一个CSS文件变化,它会在下一次全页面加载进行充电。

On a multi-page app, if a CSS file changes it will be recharged on the next full page load.

在一个单页的应用程序,用户可以保持数天的工作,从来没有充值,其中CSS文件中声明的主页。用户将不会看到,直到按Ctrl-F5发出的更改。

On a single-page app, the user can keep working for days and never recharge the main page where the CSS files are declared. The user will never see the changes until a Ctrl-F5 is issued.

我已经想到了这一点肯定有人和有经验分享:)

I'm sure someone already thought of this and have an experience to share :)

对于我来说,使用的WebSockets不是一个选项。首先因为它是矫枉过正和第二,因为不是所有的我的客户支持该技术。同样的道理适用于所有的WebSockets回退......我不会让打我的,因为这个服务器。

For me, using WebSockets is not an option. First because it's overkill and second because not all my clients support the technology. Same reason applies to all WebSockets fallbacks... I won't keep hitting my servers because of this.

因此​​,任何想法吗? :)

So, any ideas anyone? :)

顺便说一句,我们使用AngularJS如果这可以帮助特定的解决方案。

BTW, we're using AngularJS if that can help for a specific solution.

谢谢!

推荐答案

我已经通过同样的问题得到。我的解决方案是opiniated,不得以您的审核规定作出回应:

I've getting through this same problem. My solution which is opiniated and may not respond to your criterias :

当我打包我前面的应用程序和我的服务器应用,我共享包含前端应用程序的当前版本的配置文件。

When i package my front-app and my server-app, I share a configuration file containing the current version of the front-app.

正面:我的路线75%的变化隐含调用web服务(路由变化解析)。所以每次我打电话给我的服务器时,我包括含有前应用程序的客户端版本的自定义HTTP标头(或GET / POST参数)。

Front side : 75% of my routes change implicitely call a Webservice (route change resolve). SO each time I call my server I include a custom HTTP header (or a GET/POST param) containing the client version of the front-app.

服务器端:我比较前端应用程序的版本(一个在用户的浏览器,装上一次刷新用户/加载的SPA)与共享配置文件的前端应用程序版本:

Server side : I compare the front-app version (the one in the browser of the user, loaded last time user refreshed/loaded the SPA) with the front-app version of the shared configuration file :


  • 如果版本相匹配:我什么都不做

  • 如果版本不匹配我发送自定义HTTP状态错误code(418为例)

然后前端:我补充说,任何截获418错误code和做整个应用程序的力量刷新响应拦截

Then front side: I added a response Interceptor that intercepts any 418 error code and do a force-refresh of the whole app

就是这样。基本上是检查的情况下,如果前程序的版本是最新的是一个路由的变化(即通过调用一个AJAX WS)。但是,你可以添加一些无限$超时callind专用WS每次5分钟左右...
如果需要的话我可以添加一些code。

That's it. Basically the event that "check" if the front-app version is the latest is a route change (that calls a WS via ajax). But you could add some infinite $timeout callind a dedicated WS each 5 minutes or so... I can add some code if needed.

希望这有助于;)

这篇关于检测到单页的应用程序应用程序版本变化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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