最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

javascript - Is there a way to flush the DNS of a client (browser)? - Stack Overflow

matteradmin5PV0评论

I'm going to move a website to a new server with a different IP address. I have copied all files and data and it's working well. I tested this by editing the hosts file so that I could see the new server while it wasn't public yet.

Now, I'm going to change the A and AAAA records for the website to point to the new server. They both have a TTL of one hour. I believe this means that a client may wait a maximum of one hour to renew the cached DNS records. However, I want to send my visitors directly to the new site. I was thinking of building a small webpage on the old server like this:

The site has been moved and is currently unavailable to your puter. 
<a href="/">Try again</a> in one hour.

It would be great if I could add some client-side code to tell the client and/or the client browser to flush its DNS cache. Is something like that possible?

I'm going to move a website to a new server with a different IP address. I have copied all files and data and it's working well. I tested this by editing the hosts file so that I could see the new server while it wasn't public yet.

Now, I'm going to change the A and AAAA records for the website to point to the new server. They both have a TTL of one hour. I believe this means that a client may wait a maximum of one hour to renew the cached DNS records. However, I want to send my visitors directly to the new site. I was thinking of building a small webpage on the old server like this:

The site has been moved and is currently unavailable to your puter. 
<a href="/">Try again</a> in one hour.

It would be great if I could add some client-side code to tell the client and/or the client browser to flush its DNS cache. Is something like that possible?

Share Improve this question edited Jun 22, 2013 at 10:05 asked Jun 22, 2013 at 9:54 user1544337user1544337
Add a ment  | 

2 Answers 2

Reset to default 4

Theres no way to flush a clients DNS records. But if your old server will let you, you could use an .htaccess file to rewrite the request to the new server and add a 301 permentantly moved status code.

If you don't have access to the actual web server, then you could use a page like that. Or even put a javascript redirect after 3 seconds to the new server.

But really, I would think it wouldn't hurt to just leave the old files. Update both for the next week or so to make sure the DNS changes for everyone, and then do whatever redirection you want to. It should make the transfer seem a bit more seamless. That is, unless you changed servers to add a new feature of some sorts that you couldn't on the old one.

But generally, its bad form to just tell people to e back in an hour. Maintenance screen are sometimes necessary, but you can definitely damage your traffic and user base by doing it.

With Firefox, dns.resolve() can refresh DNS of Browser.

Check https://developer.mozilla/en-US/docs/Mozilla/Add-ons/WebExtensions/API/dns/resolve

Post a comment

comment list (0)

  1. No comments so far