Revision #6 has been created by le_top on Nov 1, 2014, 2:29:03 PM with the memo:
Removed empty line to see more text in overview.
« previous (#5)
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.[...]