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