Using friendly URLs to avoid cache problem

ε祈祈猫儿з 提交于 2019-12-25 02:46:31

问题


In my application (*) I sometimes needs to open (in the default user browser) a URL with some parameters.

  • e.g.: http://www.mySite.com/myPage.php?p1=param1&p2=param2&p3=param3

On some computers, I had cache problem, even if I send different parameters, the browser opened the page with the old parameters.

I tried to add time-stamp as the first parameter:

  • e.g.: http://www.mySite.com/myPage.php?pXXX=XXX&p1=param1&p2=param2&p3=param3
  • where XXX = Now.ToString("ssmmHHddMMyy")

but still, on some computers it did not solve the problem.

I wonder if using friendly URLs will help avoiding the cache problem for all users, all browsers, all default settings etc.

  • e.g.: http://www.mySite.com/myFalsePage/param1/param2/param3

[ My source for using friendly URLs:

  • http://techie-buzz.com/how-to/create-seo-friendly-urls-using-mod-rewrite-and-php-part-1.html
  • http://techie-buzz.com/tips-and-tricks/create-seo-friendly-urls-with-mod-rewrite-and-php-part-ii.html

]

Are you aware of any dis-advantages in using this method of passing parameters?

Thanks,

Atara.

(*) My application is an exe file (VB .Net) One of the menu options of the application is opening the URL, using the user default browser:

 '-- Create temporary *.url file and open it
  Try
    Dim line1 As String = "[InternetShortcut]"
    Dim line2 As String = "URL=" & sUrl
    Dim dst As String = GetSystemPathTemp() & "myAppTemp.url"

    Dim sw As New System.IO.StreamWriter(dst, False)
    sw.WriteLine(line1)
    sw.WriteLine(line2)
    sw.Close()

    System.Diagnostics.Process.Start(Chr(34) & dst & Chr(34))   

The URL is a form, the parameters are some of the fields of the form, so that the user wont have to type them.

Usually the user fills-in the form and re-directed to a "Thank you" page.

My problem: The next time the user clicks the menu, and opens the URL\form, there should be different field values in the form, according to the current application stage, BUT on some computers\users\browsers the first URL is cached, and after that, all forms are filled with the initial fields, so the user needs to manually edit them (If he noticed the problem), otherwise I get the form results with non-accurate information - the new user notes with the previous-wrong field-values.

My form page now starts with -

<?php
header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT");   // Date in the past

Until today, it started with all the following options -

<?php
//disable all browser caching MUST BE FIRST LINES WITH NO PRECEEDING SPACES ETC
// Date in the past
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");

// always modified
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");

// HTTP/1.1
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);

// HTTP/1.0
header("Pragma: no-cache");

The file "myAppTemp.url" is updated, but the browser opens the older link.


回答1:


The URL to solve a cache problem is not the way to go. The URL should represent a method to access the content, and nothing more.

In the end, you will never be able to completely resolve the clients caching, as they can do whatever they want. However, with some sensical headers, you will be just fine.

<?php
header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past
?>

From: http://php.net/manual/en/function.header.php




回答2:


I think you are looking for the wrong answer. A client would never load cached data if the querystring is different, however if the content (the page that has the link) is cached, then you would request the same data once more, even if you expect the parameters to have changed.

This could be a problem if you on pageload generate urls dynamically. Once a user navigates away from that page, and then go back, it would have the same url on the page because THAT page was cached.

EDIT:

I think you could bypass the creation of the .url file, because windows support opening of http links directly, read this article: http://support.microsoft.com/kb/305703

That way you at least eliminate one error source for your problem.



来源:https://stackoverflow.com/questions/6521978/using-friendly-urls-to-avoid-cache-problem

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!