简体   繁体   English

有什么好的策略可以确保在开发过程中(通过ajax)重新加载资源?

[英]What is a good strategy for guaranteeing resource reloads (via ajax) during development?

I've consistently not been able to find a way to reload data to the browser. 我一直无法找到一种将数据重新加载到浏览器的方法。

For example in FF 10 - Hitting Control-Shift-R is suppose to do this. 例如,在FF 10中,假设按Control-Shift-R可以做到这一点。 Sometimes it does, some times it does not. 有时确实如此,有时却没有。

I've read that if you change the URL of the requested resource the browser will re-load the data as new. 我已经读过,如果您更改请求资源的URL,浏览器将把数据重新加载为新数据。 I believe this. 我相信这一点。 I'm going to implement it. 我要实现它。

What I'm going to do is simply us PHP to change the file name by appending a unix time-stamp to it. 我要做的就是简单地通过对PHP附加unix时间戳来更改文件名。 This will be done on each resource request. 这将在每个资源请求上完成。

I'm planning on writing a PHP maintenance script ( say updateResource.php ) that renames the resource and at the same time writes PHP code that sets the name into the PHP script. 我打算编写一个PHP维护脚本(例如updateResource.php),该脚本重命名资源,同时编写将名称设置为PHP脚本的PHP代码。

so for my .js resource 所以对于我的.js资源

file1.js 

becomes

file1_timestamp.js

and

the contents of php file go from php文件的内容来自

$file_name = file1.js

$file_name = file1_timestamp.js

PHP later writes to .htm file which javascript then knows to pull from the DOM and load the file dynamically via Ajax Call. PHP稍后会写入.htm文件,然后javascript就会知道该文件会从DOM中提取并通过Ajax Call动态加载该文件。

And this time it is not cached bc the URL changed. 这次没有缓存bc URL了。

Is this a good way to guarantee reloads? 这是保证重新加载的好方法吗?

To force client side reload, script.ts?v.xx works well and is widely used. 为了强制客户端重新加载, script.ts?v.xx可以很好地工作并且被广泛使用。 Replace xx with the current release of your application at compile time. 在编译时用当前版本的应用程序替换xx。 This way you wont have to rename the file. 这样,您将不必重命名文件。

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

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