How to stop caching with jQuery and javascript
来源:互联网 发布:手机pdf阅读器 知乎 编辑:程序博客网 时间:2024/05/21 17:27
There are many reason people want to disable or stop caching by broswer. Especially when we are dealing with dynamic content that required the latest version to be displayed on the browser. However, due to security reason there are no perfect methods in javascript that can disabled caching for all browsers. In this tutorial, i will demonstrate a few way both javascript and jQuery used to stop or disable caching by browsers.
jQuery
On the later version of jQuery v1.2 above, jQuery has provided a method to stop caching by browser with its ajax class. You can visitjQuery website to see the list of update on v1.2 and you will notice that they have now included a function to disable caching! You can either choose to control the way each individual dynamic content cached by setting the properties to true/false or you can just set a default to disabled all browser caching.
In order to determine each ajax call caching properties,
1
$.ajax({
2
url:
'test.html'
,
3
cache: false,
4
success:
function
(html){
5
$(
'#results'
).append(html);
6
}
7
});
which is being reflected on the jQuery example. And in order to disable all caching by the browser we can do the following,
1
$.ajaxSetup({cache: false}});
This will have to be placed on top of the script in order for it to work.
Javascript
The reason why browsers are able to cache a particular document is due to the url being passed to the browser are identical. In order to make it unique for each passes, we can place in a random number behind the url as shown below,
1
var
img.src =
'www.hungred.com'
+
'?'
+Math.random()*Math.random();
2
return
$(img).load(
function
()
3
{
4
alert(
'completed!'
);
5
});
This method will ensure all document to be unique for every dynamic passes you throw to the browser which i find it more reliable and useful as this method has been there for quite sometimes and almost all of the browser will support such way of retrieving dynamic content.
HTML (16/04/2009)
You can also disable or stop caching using the following meta tag,
1
<meta http-equiv=
'cache-control'
content=
'no-cache'
>
2
<meta http-equiv=
'expires'
content=
'0'
>
3
<meta http-equiv=
'pragma'
content=
'no-cache'
>
This will prevent the whole page from being cached by the browser as well.
- See more at: http://hungred.com/how-to/tutorial-stop-caching-jquery-javascript/#sthash.H1QTE3vm.dpufThere are many reason people want to disable or stop caching by broswer. Especially when we are dealing with dynamic content that required the latest version to be displayed on the browser. However, due to security reason there are no perfect methods in javascript that can disabled caching for all browsers. In this tutorial, i will demonstrate a few way both javascript and jQuery used to stop or disable caching by browsers.
jQuery
On the later version of jQuery v1.2 above, jQuery has provided a method to stop caching by browser with its ajax class. You can visitjQuery website to see the list of update on v1.2 and you will notice that they have now included a function to disable caching! You can either choose to control the way each individual dynamic content cached by setting the properties to true/false or you can just set a default to disabled all browser caching.
In order to determine each ajax call caching properties,
1
$.ajax({
2
url:
'test.html'
,
3
cache: false,
4
success:
function
(html){
5
$(
'#results'
).append(html);
6
}
7
});
which is being reflected on the jQuery example. And in order to disable all caching by the browser we can do the following,
1
$.ajaxSetup({cache: false}});
This will have to be placed on top of the script in order for it to work.
Javascript
The reason why browsers are able to cache a particular document is due to the url being passed to the browser are identical. In order to make it unique for each passes, we can place in a random number behind the url as shown below,
1
var
img.src =
'www.hungred.com'
+
'?'
+Math.random()*Math.random();
2
return
$(img).load(
function
()
3
{
4
alert(
'completed!'
);
5
});
This method will ensure all document to be unique for every dynamic passes you throw to the browser which i find it more reliable and useful as this method has been there for quite sometimes and almost all of the browser will support such way of retrieving dynamic content.
HTML (16/04/2009)
You can also disable or stop caching using the following meta tag,
1
<meta http-equiv=
'cache-control'
content=
'no-cache'
>
2
<meta http-equiv=
'expires'
content=
'0'
>
3
<meta http-equiv=
'pragma'
content=
'no-cache'
>
This will prevent the whole page from being cached by the browser as well.
- See more at: http://hungred.com/how-to/tutorial-stop-caching-jquery-javascript/#sthash.H1QTE3vm.dpufThere are many reason people want to disable or stop caching by broswer. Especially when we are dealing with dynamic content that required the latest version to be displayed on the browser. However, due to security reason there are no perfect methods in javascript that can disabled caching for all browsers. In this tutorial, i will demonstrate a few way both javascript and jQuery used to stop or disable caching by browsers.
jQuery
On the later version of jQuery v1.2 above, jQuery has provided a method to stop caching by browser with its ajax class. You can visitjQuery website to see the list of update on v1.2 and you will notice that they have now included a function to disable caching! You can either choose to control the way each individual dynamic content cached by setting the properties to true/false or you can just set a default to disabled all browser caching.
In order to determine each ajax call caching properties,
1
$.ajax({
2
url:
'test.html'
,
3
cache: false,
4
success:
function
(html){
5
$(
'#results'
).append(html);
6
}
7
});
which is being reflected on the jQuery example. And in order to disable all caching by the browser we can do the following,
1
$.ajaxSetup({cache: false}});
This will have to be placed on top of the script in order for it to work.
Javascript
The reason why browsers are able to cache a particular document is due to the url being passed to the browser are identical. In order to make it unique for each passes, we can place in a random number behind the url as shown below,
1
var
img.src =
'www.hungred.com'
+
'?'
+Math.random()*Math.random();
2
return
$(img).load(
function
()
3
{
4
alert(
'completed!'
);
5
});
This method will ensure all document to be unique for every dynamic passes you throw to the browser which i find it more reliable and useful as this method has been there for quite sometimes and almost all of the browser will support such way of retrieving dynamic content.
HTML (16/04/2009)
You can also disable or stop caching using the following meta tag,
1
<meta http-equiv=
'cache-control'
content=
'no-cache'
>
2
<meta http-equiv=
'expires'
content=
'0'
>
3
<meta http-equiv=
'pragma'
content=
'no-cache'
>
This will prevent the whole page from being cached by the browser as well.
- See more at: http://hungred.com/how-to/tutorial-stop-caching-jquery-javascript/#sthash.H1QTE3vm.dpufThere are many reason people want to disable or stop caching by broswer. Especially when we are dealing with dynamic content that required the latest version to be displayed on the browser. However, due to security reason there are no perfect methods in javascript that can disabled caching for all browsers. In this tutorial, i will demonstrate a few way both javascript and jQuery used to stop or disable caching by browsers.
jQuery
On the later version of jQuery v1.2 above, jQuery has provided a method to stop caching by browser with its ajax class. You can visitjQuery website to see the list of update on v1.2 and you will notice that they have now included a function to disable caching! You can either choose to control the way each individual dynamic content cached by setting the properties to true/false or you can just set a default to disabled all browser caching.
In order to determine each ajax call caching properties,
1
$.ajax({
2
url:
'test.html'
,
3
cache: false,
4
success:
function
(html){
5
$(
'#results'
).append(html);
6
}
7
});
which is being reflected on the jQuery example. And in order to disable all caching by the browser we can do the following,
1
$.ajaxSetup({cache: false}});
This will have to be placed on top of the script in order for it to work.
Javascript
The reason why browsers are able to cache a particular document is due to the url being passed to the browser are identical. In order to make it unique for each passes, we can place in a random number behind the url as shown below,
1
var
img.src =
'www.hungred.com'
+
'?'
+Math.random()*Math.random();
2
return
$(img).load(
function
()
3
{
4
alert(
'completed!'
);
5
});
This method will ensure all document to be unique for every dynamic passes you throw to the browser which i find it more reliable and useful as this method has been there for quite sometimes and almost all of the browser will support such way of retrieving dynamic content.
HTML (16/04/2009)
You can also disable or stop caching using the following meta tag,
1
<meta http-equiv=
'cache-control'
content=
'no-cache'
>
2
<meta http-equiv=
'expires'
content=
'0'
>
3
<meta http-equiv=
'pragma'
content=
'no-cache'
>
This will prevent the whole page from being cached by the browser as well.
- See more at: http://hungred.com/how-to/tutorial-stop-caching-jquery-javascript/#sthash.H1QTE3vm.dpufjQuery
On the later version of jQuery v1.2 above, jQuery has provided a method to stop caching by browser with its ajax class. You can visit jQuery website to see the list of update on v1.2 and you will notice that they have now included a function to disable caching! You can either choose to control the way each individual dynamic content cached by setting the properties to true/false or you can just set a default to disabled all browser caching.
In order to determine each ajax call caching properties,
1 $.ajax({2 url: 'test.html',3 cache: false,4 success: function(html){5 $('#results').append(html);6 }7 });
which is being reflected on the jQuery example. And in order to disable all caching by the browser we can do the following,
1 $.ajaxSetup({cache: false}});
This will have to be placed on top of the script in order for it to work.
Javascript
The reason why browsers are able to cache a particular document is due to the url being passed to the browser are identical. In order to make it unique for each passes, we can place in a random number behind the url as shown below,
1 var img.src = 'www.hungred.com'+'?'+Math.random()*Math.random();2 return $(img).load(function()3 {4 alert('completed!');5 });This method will ensure all document to be unique for every dynamic passes you throw to the browser which i find it more reliable and useful as this method has been there for quite sometimes and almost all of the browser will support such way of retrieving dynamic content.
HTML (16/04/2009)
You can also disable or stop caching using the following meta tag,
1 <meta http-equiv='cache-control' content='no-cache'>2 <meta http-equiv='expires' content='0'>3 <meta http-equiv='pragma' content='no-cache'>This will prevent the whole page from being cached by the browser as well.
- How to stop caching with jQuery and javascript
- How to start and stop exe
- How To Optimize Your Site With HTTP Caching
- How to Create Login Form with CSS3 and jQuery
- How to check and uncheck a checkbox with jQuery
- How to learn to stop worrying and love machine learning
- How To Start / Restart / Stop Network and Routing Service
- how to find background job and stop them
- how to start and stop android service by using adb
- How to Use C++ With PHP and JQuery to Make Neat Apps
- How to get textbox value with jQuery
- how to add Javascript and CSS in page layout with sharepoint 2013
- How To Do Everything with JavaScript
- How to Stop a Thread
- Stop being greedy and stop to rest!
- How to: Enable ASP.NET Output Caching
- EclipseLink:How to use EclipseLink Caching
- JavaScript Errors and How to Fix Them
- Axure rp 6.5 软件基础入门学习目录
- java公式解析器学习与开发(2)——前缀表达式
- C++流
- 快速幂取模
- 学习设计模式之禅——代理模式
- How to stop caching with jQuery and javascript
- 要不要加油
- Installing and Configuring GoldenGate Veridata Agent
- 递归算法简析
- 接口功能测试策略
- Python模块学习 ---- datetime
- hdu 1008 Elevator
- Google云计算三大核心技术之HBase
- hdu——3791——二叉树搜索树