开发者

Why do ASP pages take a minute or two to reflect changes?

开发者 https://www.devze.com 2023-03-12 09:38 出处:网络
My PHP pages and HTML pages instantly reflect any change I make to them, making it very easy to view my change开发者_StackOverflow中文版s as I develop a page.

My PHP pages and HTML pages instantly reflect any change I make to them, making it very easy to view my change开发者_StackOverflow中文版s as I develop a page.

ASP pages never show any change on the first refresh, and only show their updated content after a 1-2 minute wait. This makes development extremely slow and frustrating.

Why does this happen? Is it simply a quirk of my hosting service that I will have to accept, or is there something I can do about it?


Sounds more like a client problem than a code problem. I'm willing to bet the browser is keeping the page in the cache, instead of requesting a new page every time. You can test this by forcing a no-cache page refresh using CTRL-F5 (should work in most browsers).

After that, you can prevent caching in a handful of ways.

For classic asp:

<%
    Response.Expires = -1
    Response.AddHeader "pragma", "no-cache" 
    Response.AddHeader "cache-control", "private, no-cache, must-revalidate"
%>

For ASP.NET markup:

<%@ OutputCache Duration="-1" VaryByParam="none" %> 

For ASP.NET code behind:

Response.Expires = -1;
Response.CacheControl = "no-cache";

HTML (no guarantee browsers will honor meta tags)

<head>
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="expires" content="-1">
    <meta http-equiv="cache-control" content="private, no-cache, must-revalidate">
<head>


It could be a product of the host that you are using but if it is really minutes of waiting then I think you might have a bigger problem. Can you give me more information? Are you using Visual Studio or another IDE/Server combination?

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号