Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

HTML Introduction to HTML and CSS (2016) HTML: The Structural Foundation of Web Pages and Applications Image Tags

having issues on a video

one of the videos tells me to copy and paste a image url and says it should be a different image everytime i refresh the page on my end it is not a different image every time i refresh

2 Answers

Steven Parker
Steven Parker
231,269 Points

Your browser is probably trying to be efficient by caching the image and not getting it again from the network. Usually there's a way in the browser to tell it to refresh without using the cache (I think it's Ctrl+F5 in Chrome).

I have also "tricked" browsers by using JavaScript to add some random junk to the URL as a query string. Then it always re-fetches because the URL isn't in the cache. For example:

document.querySelector("img").src += "?nocache=" + Math.random();

Use a more specific selector if your image is not the first one on the page.

thank you that worked but when you click the refresh button with your cursor it does not change the image is that a problem on my end

Steven Parker
Steven Parker
231,269 Points

IT doesn't change it even with the script code installed?

If you mean without it, the standard refresh will almost certainly use caching. But depending on the browser, perhaps a Ctrl+click (or shift+click or alt+click?) would load without the cache.