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.

HTML Introduction to HTML and CSS Adding a New Web Page Write the HTML

Don-Alex Antoine
Don-Alex Antoine
7,487 Points

My image doesn't change to a new image everytime i refresh the page

<img src="https://placeimg.com/200/200/tech" alt="Tech">

The image is not changing into a new image every time I refresh the page. This is the code I used.

4 Answers

Steven Parker
Steven Parker
210,475 Points

Your browser is probably caching the image as an efficiency measure. Most browsers have a separate refresh function that disregards the cache you could try, or a configuration option to clear the cache.

You could also add a small JavaScript component to add a random query string to the URL to prevent caching. I provided some sample code for this in an answer to a previous similar question.

Chintan Ray
seal-mask
.a{fill-rule:evenodd;}techdegree
Chintan Ray
Full Stack JavaScript Techdegree Student 12,309 Points

You can also simply hold down the shift key while refreshing the page. It works for me. I am not familiar with JavaScript, but this is a crude way of clearing the cached images.

Don-Alex Antoine
Don-Alex Antoine
7,487 Points

You are right. it is caching the images as an efficiency measure.

Parminder Kaur
Parminder Kaur
3,596 Points

I was facing the same problem, and pressing shift key along with the refresh button worked for me. Thanks!