Home > Tips & Tricks > JavaScript Hard Refresh of Current Page

JavaScript Hard Refresh of Current Page

Hello friends, today I was working on a project and in the project I need to refresh the current page without loading the cache. So I found the solution and I think it will share with you.

So in this trick, I’ll show you how to hard refresh current page using the javascript code. We just need to add simple one line of code.

You can add this line of code in the element as inline javascript or you can make a function on the event hits. So when the event occur you can call the hard refresh code line.

JavaScript Hard Refresh Current Page

Let’s see the code line what you can use to reload the whole page from server not from the cache. So we will use reload() function of location object.

As you see we use the reload() function and pass the true parameter to load the page from the server. If you don’t pass the true parameter then it will load the page from the cache.

So you can use the above function as following code.

When you click on the button then the reload() function call and force the page to load from the server. You can use this function on any event but not on the window.load and document.ready, becasue it will be infinite.

Being Tricky 😉

Photo of author

About Aman Mehra

Hey there! I'm Aman Mehra, a full-stack developer with over six years of hands-on experience in the industry. I've dedicated myself to mastering the ins and outs of PHP, WordPress, ReactJS, NodeJS, and AWS, so you can trust me to handle your web development needs with expertise and finesse. In 2021, I decided to share my knowledge and insights with the world by starting this blog. It's been an incredible journey so far, and I've had the opportunity to learn and grow alongside my readers. Whether you're a seasoned developer or just dipping your toes into the world of web development, I'm here to provide valuable content and solutions to help you succeed. So, stick around, explore the blog, and feel free to reach out if you have any questions or suggestions. Together, let's navigate the exciting world of web development!

Leave a Comment