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

Does http://placeimg.com really allows us to make a different image appear each time F5 is pressed ? Still the same pic'

Even with different scales and names (http://placeimg.com/400/400/nature or /people or /tech or whatever in the end of the link), it only makes the same image appear when I reload the page. Does anyone knows why ? Or maybe it is simply because this has changed since the video was made

4 Answers

Steven Parker
Steven Parker
230,274 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). On 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, the no-cache reload worked.

Steven Parker
Steven Parker
230,274 Points

It would go in a JavaScript file, if your project has one, and if not between "script" tags as the last part of the HTML body:

   <script>  code would go here  </script>
</body>

Alright, thank you for the answer, that is clear ^^

Amy Chatas
seal-mask
.a{fill-rule:evenodd;}techdegree
Amy Chatas
Front End Web Development Techdegree Student 158 Points

Super helpful - the video doesn't give that detail for making the images change. When I add as you indicate - It works!

<script> document.querySelector("img").src += "?nocache=" + Math.random(); </script> </body>

Yousef El-Chafei
Yousef El-Chafei
762 Points

An easier way I found was to do the command Ctrl+f5 this command forces a no-cache.

Hope this helps