GithubHelp home page GithubHelp logo

yarii's Introduction

YARII, Responsive Images!


- ALPHA VERSION - USE WITH CAUTION -


What is it ?

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.

How does it work ?

YARII's action is divided in 2 steps:

  1. 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.

  2. 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.

So what about browsers without Javascript enabled ?

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.

Installation

Server side

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

Client side

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

Changelog

0.0.1

  • Beta version

License

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.

yarii's People

Contributors

lwiesel avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.