I am trying to implement this: http://adaptive-images.com/ into a website. It will rely on JS-Cookies that will get the screen's resolution so the PHP script that adapts the image sizes knows what resolution to deliver. Unfortunately it somehow fails to set the cookie (and falls back to 480 resolution...) and I have no idea why. What it does is simply:
<script type="text/javascript">
document.cookie='resolution='+Math.max(screen.width,screen.height)+'; expires=; path=/';
</script>
right in the head of the document. Yet, the cookie never seems to be set, I will only see (they should appear in the Resources Part of the Chrome DevTools, right?) the GoogleAnalytics-created ones (yet, this does not seem to be the problem as removing GA makes no difference).
I never used JS cookies before, but from what I can read on the web the syntax seems to be perfectly fine and also I do not get any kind of error messages in the console or elsewhere, it just seems to ignore the cookie setting action.
A long story short: I have no idea what's going on here?
Thanks!
EDIT: Maybe this is a PHP sided problem so I'll add this part too. What happens is the following:
First off:
$resolutions = array(1920,1382, 992, 768, 480);
Then:
if (is_numeric($_COOKIE['resolution'])) {
$client_width = (int) $_COOKIE["resolution"];
rsort($resolutions);
$resolution = $resolutions[0];
foreach ($resolutions as $break_point) {
if ($client_width <= $break_point) {
$resolution = $break_point;
}
}
}
Yet, the script will aways return a 480 resolution, even though my screen is 1920? As far as I get the code it should be returning 1920 so I guess it seems to use the fallback in case $_COOKIE['resolution']
is not set, which would be going back to 480.