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 trialZane Wilson
Python Development Techdegree Student 8,747 PointsPlaceimg random image
In the training video, when Treasure refreshes the page - it loads a new image every time. However, when I refresh the page, the image stays consistent and their is no randomization.
Is this because of the browser I'm using or is this something that I'm doing wrong when I'm inserting the code?
Code for the header is below -
<header> <img src="https://placeimg.com/400/400/people" alt="Drawing of Jane Smith" class="profile-image"> <h1 class="tag name">Hello, Iām Zane.</h1> <p class="tag location">My home is New York, New York.</p> </header>
Thanks in advance!
1 Answer
Steven Parker
231,275 PointsHere's the answer I've given previously (as Regan observed), complete with syntax coloring:
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).
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.
Regan Layman
13,892 PointsRegan Layman
13,892 Pointscopied from Steven Parker 2/4/20 comment
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).
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.