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 Test: Creating an HTML Element

on the place.img page, I can't put in 400 by 400 and I cannot get the images to change every time I click on refresh

On placeimg.com The height and width boxes won't let me change the size, so I just put 400 x 400 in my code and it pulled up the correct image; however, it won't change the image every time I refresh like it did in the tutorial.

1 Answer

Steven Parker
Steven Parker
228,991 Points

Once you fetch an image, your browser caches it and then gives you the same one back when you reference the same URL instead of fetching a new one.

You can add a fake query string to your image URL to prevent the browser from using the cached version with a line of JavaScript:

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

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