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

Placeholder not displaying different images when the web page is refreshed

I observed that when I pasted the url - http://placeimg.com/400/400/people in my src tag, it was displaying only one image despite refreshing the page.

Could anyone help with the reason(s) for the above mentioned observation?

Thanks in advance.

1 Answer

Steven Parker
Steven Parker
231,236 Points

Most likely, your browser is trying to be efficient by caching the image. Try doing a no-cache reload if your browser has that function (most do, in Chrome it's Ctrl-F5).

You can also use a bit of JavaScript to change the URL each time to prevent the cached copy from being used:

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

Note that this particular script only targets the first image on the page.

Thanks for your advice, I tried Ctrl-F5 and it worked