YARII is a way to implement responsive images without any img markup changes, thanks to server-side modules.
YARII detects screen resolution, bandwith and HD screens to serve the exact image needed.
On top of that, a JQuery script ensure beautiful progressive enhancement on js-able browsers.
YARII has not been entirely created from scratch. Some parts of code are forked from these great projects :
Go check them, they really are inspiring projects.
YARII's action is divided in 2 steps:
-
YARII intercepts images requests on server side and send an appropriate image to the client depending on its resolution (also detecting HD screens) and its bandwidth.
-
YARII starts reloading full quality image as background task, if necessary (i.e. image quality too low for the client). When load is complete, the low quality image get replaced, optionally with animation.
YARII is based on a Progressive Enhancement philosophy. Recent publications stated that images should be sent to non-js browser in low quality by default (mobile first behavior).
YARII let you choose wether you want to sent low quality images or original images to non-js browsers.
First, put the yarii-srv
folder wherever you want on your server.
Then, add these lines in your .htaccess
file. Don't forget to adapt the path to your configuration.
<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine On
# YARII -----------------------------------------------------------------------------------
# Add any directories you wish to omit from the YARII process on a new line, as follows:
# RewriteCond %{REQUEST_URI} !ignore-this-directory
# RewriteCond %{REQUEST_URI} !and-ignore-this-directory-too
# RewriteCond %{REQUEST_URI} !assets
# don't apply the YARII behaviour to images inside YARII's cache folder:
RewriteCond %{REQUEST_URI} !yarii-cache
RewriteCond %{REQUEST_URI} \/yarii\.
# Send any GIF, JPG, or PNG request that IS NOT stored inside one of the above directories
# to yarii.php so we can select appropriately versions
RewriteRule \.(?:jpe?g|gif|png|JPG)$ path/to/yarii-srv/yarii.php
# END YARII -------------------------------------------------------------------------------
</IfModule>
If you don't have access to your .htaccess
or if you want to select the folders where YARII applies, just create one in your image directory, assuming you regrouped your images in one location. Otherwise, just create one file per directory.
Soon : the "How to configure YARII" page
Add links to the folowing javascript files:
yarii-first.js
(resolution detection)yarii-second.js
(bandwidth detection)yarii-third.js
(background task reload of full quality images)
To enable full quality images reloading, add this line at the end of the page, before </body>
:
<script>
$('img').yarii();
</script>
That's it ! You're done !
Soon : the "How to configure YARII" page
0.0.1
- Beta version
The MIT License (MIT)
Copyright (c) 2013 ChessyWeb (Laurent WIESEL)
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.