Hi everyone,
Thanks for your interest in this project!
I can see there's some debate about whether the system loads the large image first or not. The short answer is "no" but the long answer is "very rarely" and I'm tracking down the reason so it can be fixed. Here's how the process works:
The browser loads the site, starting with the HTML. It reaches the JavaScript which is in the <head> and immediately executes that JS. The JS asks the browser what the maximum screen size of the device is, and stores that number in a cookie. The rest of the HTML then loads. As soon as the browser hit's an <img> tag it attempts to load the image from the server. But, because of the .htaccess rule the server - instead of simply sending the JPG - it first loads the PHP. The PHP then has a look to see if there's a cookie with the screen size - if there is it simply sends an appropriately sized JPG back (or generates a new JPG if needed).
As you've seen though, that isn't always what is happening and so far I have two potential reasons:
The first is that I recently made the JS an external file instead of in-line in the head. Which means the browser may be loading that at the same time as the HTML, and may in fact reach the HTML images before the JS has had chance to run - which will mean that on the first request there is no cookie. I think this is the most likely explanation, and if so I'll simply revert back to the JS being in the head instead of a file. To be honest I was going to revert it back to this on the next release anyway. The JS itself is now far simpler than in the 1.0 release - it's back to being a 1-line call, so it doesn't make sense to be in its own file anyway.
The second potential reason is to do with a recent bug report on Firefox: There appears to be a minor bug in how FF works, and on the very first load of the page (and only that load), the browser does not send the cookie data along with the image. Which means that the PHP script falls back to serving the original image that's linked to from the HTML. Which, for my example site, is a ridiculously large 850kb image. A bug report has been filed with Mozilla: https://bugzilla.mozilla.org/show_bug.cgi?id=680462
I'm currently investigating which is the cause, and will hopefully be able to roll out a v1.1.1 bug-fix release in the coming day or two.
I am also looking at getting the project put onto GitHub so this kind of feedback is handled faster and more effectively.
Thanks everyone for your interest and time
-Matt