Difference between #5 and #6 of
Provide SVG when the browser supports it, else PNG (using CHtml::image overload)

Changes

Title unchanged

Provide SVG when the browser supports it, else PNG (using CHtml::image overload)

Category unchanged

Tips

Yii version unchanged

Tags unchanged

svg, CHtml::image, images

Content changed

Modern browsers support SVG, older browsers do not.
 
This replacement for CHtml::image() allows you to handle to propose SVG in an efficient way with PNG as a fallback.

On the first load, it will wrap images in a structure that holds both the SVG and PNG alternative. In that case it is the browser that "selects" the right image.
During that load, the browser will also set a cookie indicating that it supports SVG as an image or not.

On the second load, or for subsequent ajax loads, the cookie will tell if the browser supports SVG for images. So instead of rendering a complex structure, either the SVG is rendered or the PNG is rendered. This is more efficient.
[...]
1 0
1 follower
Viewed: 10 045 times
Version: 1.1
Category: Tips
Written by: le_top
Last updated by: le_top
Created on: Nov 1, 2014
Last updated: 9 years ago
Update Article

Revisions

View all history