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 trialjeanludovicblanchon
318 PointsDoes 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
231,184 PointsMost 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.
jeanludovicblanchon
318 PointsAlright, thank you for the answer, that is clear ^^
Amy Chatas
Front End Web Development Techdegree Student 158 Points@stevenparker thanks!
Amy Chatas
Front End Web Development Techdegree Student 158 PointsSuper 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
762 PointsAn easier way I found was to do the command Ctrl+f5 this command forces a no-cache.
Hope this helps
Nathaniel Ohiare
109 PointsNathaniel Ohiare
109 PointsThanks, the no-cache reload worked.
Amy Chatas
Front End Web Development Techdegree Student 158 PointsAmy Chatas
Front End Web Development Techdegree Student 158 Pointswhere would this language be added?
Steven Parker
231,184 PointsSteven Parker
231,184 PointsIt 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: