“&rnd=”的目的是什么? http请求中的参数?
为什么某些 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这可能是为了确保页面/图像/任何内容不会从用户的缓存中获取。如果链接每次都不同,那么浏览器将从服务器而不是从缓存获取它,以确保它是最新版本。
它还可以跟踪人们在网站上的进度。最好用一个小故事来解释:
不过,我们所能做的就是提出可能性。在 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:
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.
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.
它几乎总是用于缓存清除。
It's almost always for cache-busting.
正如其他人所建议的那样。这种行为通常用于避免在调用返回动态内容数据的页面时出现缓存问题。
例如,假设您有一个页面获取一些当前用户信息,例如“mysite.com/CurrentUserData”。现在,在第一次调用此页面时,将按预期返回用户数据,但根据时间和缓存设置,第二次调用可能会返回相同的数据 - 即使预期数据可能已更新。
缓存的主要原因当然是为了优化频繁请求的速度。但在不需要这样做的情况下,添加随机值作为查询字符串参数是一种广泛使用的解决方案。
然而,还有其他方法可以解决这个问题。例如,如果您使用 javascript/JQuery 执行 Ajax 请求。您可以在调用中将缓存设置为 false...
您还可以为文档加载时的所有页面调用更改它...
如果您要执行 MVC 应用程序,您甚至可以使用以下命令禁用控件操作方法上的缓存像这样的属性...
(感谢 这里)
我敢假设 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...
you could also change it for all page calls on document load with...
If you were to do an MVC application, you can even disable the caching on the control action methods with an attribute like so...
(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.