“&rnd=”的目的是什么? http请求中的参数?

发布于 2024-12-11 02:06:30 字数 75 浏览 0 评论 0原文

为什么某些 Web 应用程序使用 http-get 参数 rnd?其目的是什么?使用这个参数可以解决什么问题?

Why do some web-applications use the http-get parameter rnd? What is the purpose of it? What problems are solved by using this parameter?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

空宴 2024-12-18 02:06:30

这可能是为了确保页面/图像/任何内容不会从用户的缓存中获取。如果链接每次都不同,那么浏览器将从服务器而不是从缓存获取它,以确保它是最新版本。

它还可以跟踪人们在网站上的进度。最好用一个小故事来解释:

  1. 用户访问 example.com。所有链接都被赋予相同的随机数(假设为 4)。
  2. 用户在新窗口/选项卡中打开链接,链接为page2.php?rnd=4。该页面中的所有链接都被赋予随机数 7。
  3. 用户可以从原始选项卡或新选项卡中单击 page3.php 的链接,服务器上的分析软件可以通过是否有 rnd=4 来判断是哪个链接或 rnd=7。

不过,我们所能做的就是提出可能性。在 URL 中放入 rnd= 没有一个标准的理由,如果不查看服务器软件,我们就无法知道网站设计者的动机。

This could be to make sure the page/image/whatever isn't taken from the user's cache. If the link is different every time then the browser will get it from the server rather than from the cache, ensuring it's the latest version.

It could also be to track people's progress through the site. Best explained with a little story:

  1. A user visits example.com. All the links are given the same random number (let's say 4).
  2. The user opens a link in a new window/tab, and the link is page2.php?rnd=4. All the links in this page are given the random number 7.
  3. The user can click the link to page3.php from the original tab or the new one, and the analytics software on the server can tell which one by whether it has rnd=4 or rnd=7.

All we can do is suggest possibilities though. There's no one standard reason to put rnd= in a URL, and we can't know the website designer's motives without seeing the server software.

姜生凉生 2024-12-18 02:06:30

Internet Explorer 和其他浏览器将读取图像 URL、下载图像并将其存储在缓存中。

如果您的应用程序要定期更新图像,并且您希望用户看不到缓存的图像,则每次的 URL 都需要是唯一的。

因此,添加随机字符串可确保该字符串是唯一的并每次下载到缓存中。

Internet Explorer and other browsers will read an image URL, download the image, and store it in a cache.

If your application is going to be updating the image regular, and so you want your users to not see a cached image, the URL needs to be unique each time.

Therefore, adding a random string ensures this will be unique and downloaded into the cache each time.

潜移默化 2024-12-18 02:06:30

它几乎总是用于缓存清除。

It's almost always for cache-busting.

你列表最软的妹 2024-12-18 02:06:30

正如其他人所建议的那样。这种行为通常用于避免在调用返回动态内容数据的页面时出现缓存问题。

例如,假设您有一个页面获取一些当前用户信息,例如“mysite.com/CurrentUserData”。现在,在第一次调用此页面时,将按预期返回用户数据,但根据时间和缓存设置,第二次调用可能会返回相同的数据 - 即使预期数据可能已更新。

缓存的主要原因当然是为了优化频繁请求的速度。但在不需要这样做的情况下,添加随机值作为查询字符串参数是一种广泛使用的解决方案。

然而,还有其他方法可以解决这个问题。例如,如果您使用 javascript/JQuery 执行 Ajax 请求。您可以在调用中将缓存设置为 false...

$.ajax({url: 'page.html', cache: false});

您还可以为文档加载时的所有页面调用更改它...

$.ajaxSetup({cache: false}});

如果您要执行 MVC 应用程序,您甚至可以使用以下命令禁用控件操作方法上的缓存像这样的属性...

[OutputCache(NoStore = true, Duration = 0, VaryByParam = "*")]
public ActionResult NonCacheableData()
{
    return View();
}

(感谢 这里

我敢假设 IIS 中也有一些设置,您可以应用它来获得相同的效果 - 尽管我还没有做到这一点。

As has been suggested by others. This kind of behaviour is usually used to avoid caching issues when you are calling a page that returns dynamic content data.

For example, say you have a page that gets some current user information such as "mysite.com/CurrentUserData". Now on the first call to this page, the user data will be returned as expected, but depending on the timing and caching settings, the second call may return the same data - even though the expected data may have been updated.

The main reason for caching is of course to optimise the speed of frequent request. But in the instance where this is not wanted, adding a random value as a query string parameter is known to be a widely used solution.

There are however other ways to get around this issue. For example if you were doing an Ajax request with javascript/JQuery. You could set the cache to false in your call...

$.ajax({url: 'page.html', cache: false});

you could also change it for all page calls on document load with...

$.ajaxSetup({cache: false}});

If you were to do an MVC application, you can even disable the caching on the control action methods with an attribute like so...

[OutputCache(NoStore = true, Duration = 0, VaryByParam = "*")]
public ActionResult NonCacheableData()
{
    return View();
}

(thanks to a quick copy and paste from here)

I dare say there are also settings in IIS you could apply to get the same affect - though I have not been that far with this yet.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文