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

Brendan Berg-Jacobson
Brendan Berg-Jacobson
1,067 Points

Image tag video.

Hi, I'm looking at the image tag video and we just put in the address from placeimg.com to load random pictures every time the page refreshes. The problem I'm having is that it is not loading a random image after refreshing the page. It just loads the same image every time. What have I done wrong?

1 Answer

Steven Parker
Steven Parker
231,271 Points

You have probably done nothing wrong at all. Your browser is likely caching the image in an attempt to be efficient. See if your browser has a "no-cache refresh" option and try that.

There's also a trick you can do with a bit of JavaScript to add a query string onto the URL with a random number in it. Then it never matches anything in the cache.

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

Note that this particular script will only work for the first image on the page.