Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.


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
216,083 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.