如何重新加载"index.html"没有手动干预的angularJS中? [英] How to reload "index.html" in angularJS without manual intervention?

查看:158
本文介绍了如何重新加载"index.html"没有手动干预的angularJS中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用AngularJS开发的网站,index.html是应用程序的根目录.

I have a website developed in AngularJS, and index.html serves the root of the application.

所有JS和CSS版本都保留在index.html本身中,这意味着要向用户反映任何更改,"index.html"将在浏览器中重新加载.(如果我错了,请纠正我). 这是一个问题,因为用户可能会在浏览器中打开我们网站的标签,并且我们已经发布了新版本.直到未触发手动刷新"并且未重新加载"index.html"的时间之前,此版本才会在用户的浏览器中发布.因此,这有可能导致用户不会使用我们的最新版本.

All the JS and CSS versions are maintained in the index.html itself, which means for any changes to reflect to the user, "index.html" is to be reloaded at the browser.(correct me if I am wrong here). This is a problem, since there could be chances that the user has a tab opened of our website in his browser and we have published a new release. This release will not be published at user's browser till the time a "Manual refresh" is not triggered and "index.html" is not reloaded and hence bring up the possibility that the user will not be using our latest release.

我们已经编写了一个框架,可以通过从Web服务器发送最新版本并将其与浏览器中的当前版本进行比较,并在检测到版本后,重新加载所有资源,并自动触发重新加载.此修复程序运行良好,但问题又来了,如何首次将此版本发布到所有用户的浏览器?

We have written a framework to reload all resources once a release is detected by sending the latest version from web-server and comparing this with the current version in the browser and trigger a reload automatically. This fix works fine, but the problem again is, how to publish this release first time to all user's browser?

我希望你能解决我的问题?让我知道其他情况.

I hope you get my problem? let me know otherwise.

推荐答案

这是不可能的.如果尚无实现该功能的代码,则无法强制打开页面进行刷新.您将不得不等到用户自己刷新它,浏览器缓存到期以及用户与服务器之间的任何中间缓存.

This is not possible. There is no way to force an open page to refresh if it does not already have code to implement that feature. You will have to wait until the user refreshes it themselves, and the browser cache expires, and any intermediate caches between the user and your servers.

如果您不熟悉"HTTP缓存",建议您进行搜索以了解"HTTP缓存"以及缓存清除".通常,您可能需要考虑将index.html做成一个小的文件,该文件在<script>标记中引用您的大文件,将index.html的缓存控制设置得非常低,并在大文件上使用缓存清除技术.

I recommend searching to learn about "HTTP caching" if you are not already familiar, as well as "cache busting." In general, you may want to consider making index.html a small file that references your big files in <script> tags, setting the cache control for index.html very low, and use cache busting techniques on your big files.

但是对于您的第一个版本,无法使打开的选项卡或现有的缓存无效.如果这将导致您的服务器出现问题,请阅读"API版本控制"以获取不同的处理方式.

But for your first release, there is no way to invalidate open tabs or existing caches. If this will cause a problem with your server, read up on "API versioning" for different ways to handle it.

这篇关于如何重新加载"index.html"没有手动干预的angularJS中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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