forked from praveenvijayan/grunt-html-validation
-
Notifications
You must be signed in to change notification settings - Fork 1
/
_tempvlidation.html
644 lines (471 loc) · 35.6 KB
/
_tempvlidation.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
<!DOCTYPE html>
<!--[if IEMobile 7 ]><html class="no-js iem7"><![endif]-->
<!--[if lt IE 9]><html class="no-js lte-ie8"><![endif]-->
<!--[if (gt IE 8)|(gt IEMobile 7)|!(IEMobile)|!(IE)]><!--><html class="no-js" lang="en"><!--<![endif]-->
<head>
<!--
___ ___ ___ ___ ___ ___ _______
| \| __/ __/ _ \| \_ _|_ / __|
| |) | _| (_| (_) | |) | | / /| _|
|___/|___\___\___/|___/___/___|___|
-->
<meta charset="utf-8">
<title>Simple Responsive image technique - Decodize</title>
<meta name="author" content="Praveen Vijayan">
<meta name="description" content="Serving resized images in Responsive Web Design.">
<meta name="keywords" content="images, Responsive Web Design (RWD), adaptive images, CDN, Image resize, mobile">
<!-- http://t.co/dKP3o1e -->
<meta name="HandheldFriendly" content="True">
<meta name="MobileOptimized" content="320">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="author" href="https://plus.google.com/111067440252423767432/posts">
<script>
var cwResImg = function () {
var cwBpArry = [1382, 992, 768, 480], //Image breakpoint arrays
currIndex,
cwResImgVal = Math.max(screen.width,screen.height),
hdpi = window.devicePixelRatio > 1 ? window.devicePixelRatio : 1,
rwdImgId = "rwdimg-"+Math.floor(Math.random()*1000),
tpl='<img src="{src}" alt="{alt}" title="{title}" id="{rwdImgId}">';
cwBpArry.push(cwResImgVal);
cwBpArry.sort(function(a,b){return a-b});
if(Array.prototype.indexOf){
currIndex = cwBpArry.indexOf(cwResImgVal) + 1;
}else{
for(var i in cwBpArry){
if(cwBpArry[i] === cwResImgVal){
currIndex = parseInt(i)+1;
}
}
}
cwBpArry[currIndex] = cwBpArry[currIndex] || cwBpArry[currIndex-1];
var imgWid = Math.max.apply(Math, cwBpArry) <= cwBpArry[currIndex] ? cwBpArry[currIndex-2] : cwBpArry[currIndex];
return {
imgWid : imgWid,
hdpi: hdpi,
rwdImg:function(arg){
var src = arg.src || arguments[0] || '',
src = src.replace(/\/s\d*\//, '/s'+imgWid * hdpi+'/'),
title = arg.title || arg.alt || arguments[1] || '',
alt = arg.alt || arg.title || arguments[2] || arguments[1] || '',
img = tpl.replace('{src}',src).replace('{title}',title).replace('{alt}',alt).replace('{rwdImgId}',rwdImgId);
document.write(img)
}
};
}()
//Iframe communication
document.domain = "decodize.com";
</script>
<link rel="canonical" href="http://decodize.com/html/simple-responsive-image-technique/">
<link href="/favicon.ico" rel="icon">
<link href="//disqus.com" rel="dns-prefetch" />
<link href="//googleusercontent.com" rel="dns-prefetch" />
<link href="//google.com" rel="dns-prefetch" />
<link href="//twitter.com" rel="dns-prefetch" />
<link href="//google-analytics.com" rel="dns-prefetch" />
<link href="//facebook.com" rel="dns-prefetch" />
<link href="http://disqus.com" rel="prefetch" /> <!– IE9+ –>
<link href="http://googleusercontent.com/" rel="prefetch" /> <!– IE9+ –>
<link href="http://google.com/" rel="prefetch" /> <!– IE9+ –>
<link href="http://twitter.com" rel="prefetch" /> <!– IE9+ –>
<link href="http://google-analytics.com" rel="prefetch" /> <!– IE9+ –>
<link href="http://facebook.com" rel="prefetch" /> <!– IE9+ –>
<!--Fonts from Google"s Web font directory at http://google.com/webfonts -->
<link href="http://fonts.googleapis.com/css?family=PT+Serif:regular,italic,bold,bolditalic" rel="stylesheet" type="text/css">
<link href="http://fonts.googleapis.com/css?family=PT+Sans:regular,italic,bold,bolditalic" rel="stylesheet" type="text/css">
<link href="/stylesheets/screen.css" media="screen, projection" rel="stylesheet" type="text/css">
<script src="/javascripts/modernizr-2.0.js"></script>
<script src="/javascripts/ender.js"></script>
<script src="/javascripts/octopress.js" type="text/javascript"></script>
<link href="http://feeds.feedburner.com/Decodize" rel="alternate" title="Decodize" type="application/atom+xml">
</head>
<body >
<header role="banner"><hgroup>
<h1><a href="/">Decodize</a></h1>
<h2>console.log</h2>
</hgroup>
</header>
<nav role="navigation"><ul class="subscription" data-subscription="rss">
<li><a href="http://feeds.feedburner.com/Decodize" rel="rss" title="subscribe via RSS">RSS</a></li>
<li><a href="http://twitter.com/praveen_vijaya" rel="twitter" title="Twitter @praveen_vijaya">Twitter</a></li>
<li><a href="https://github.com/praveenvijayan" rel="github" title="Github">Github</a></li>
<li><a href="https://delicious.com/praveenvijayan" rel="delicious" title="Delicious">Delicious</a></li>
<li><a href="https://facebook.com/praveen.vijayan0" rel="facebook" title="Facebook">Facebook</a></li>
</ul>
<form action="http://google.com/search" method="get">
<fieldset role="search">
<input type="hidden" name="q" value="site:decodize.com" />
<input class="search" type="text" name="q" results="0" placeholder="Search"/>
</fieldset>
</form>
<ul class="main-navigation">
<li><a href="/">Blog</a></li>
<li><a href="/blog/archives">Archives</a></li>
<li><a href="/about">About</a></li>
<li><a href="/projects">Projects</a></li>
</ul>
</nav>
<div id="main">
<div id="content">
<div>
<article class="hentry" role="article">
<header>
<h1 class="entry-title">Simple Responsive Image Technique</h1>
<p class="meta">
<time datetime="2013-01-04T00:19:00+05:30" pubdate data-updated="true">Jan 4<span>th</span>, 2013</time>
</p>
</header>
<div class="entry-content"><p>RWD (Responsive Web Design) is increasingly popular over past few years. One important problem faced by RWD is lack of a standardised solution to deliver resized images into multiple devices. We have wide range of device categories, screen resolutions, pixel densities and lack of bandwidth/connection detection methods, all made this process difficult. There is no simple silver bullet to solve this issue.</p>
<p>This is a quick post on a simple technique I used to create responsive image. This is a javascript solution, but it will work in javascript disabled environment by using a noscript fallback. This technique will start with mobile image first & there is no need to parse and replace image sources.</p>
<!-- more -->
<p>I’m using google picasa as my image host. I can resize images dynamically by setting width/height in the url.</p>
<p><a href="http://demos.decodize.com/responsive-images/demo.html" title="Responsive images" target="_blank">Responsive images demo</a></p>
<p>Eg:
//lh3.googleusercontent.com/-Rw0hpxt70co/ULeX80ncW3I/AAAAAAAAE6g/kIDj6u1zdyI/<strong>s640</strong>/query-loader1.jpg</p>
<p>Setting <strong>s320</strong> will create image with width/Height (resize proportionally) 320px. We can also pass width or height. Setting <strong>w320</strong> will create an image with width 320px or passing <strong>h320</strong> will constrain height of dynamically created image to 320px. Now we have our server, which can provide us different images sizes upon request.</p>
<p>You can use your own server methods or other resources like <a href="http://www.sencha.com/learn/how-to-use-src-sencha-io/">src.sencha.io</a> to resize images on the fly.</p>
<h3>Technique</h3>
<p>Using css fluid image technique scale image to viewpot. Get the device size and insert image using script.</p>
<p><strong><em>CSS</em></strong></p>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
</pre></td><td class='code'><pre><code class='css'><span class='line'><span class="nt">img</span> <span class="p">{</span>
</span><span class='line'> <span class="k">display</span><span class="o">:</span> <span class="k">block</span><span class="p">;</span>
</span><span class='line'> <span class="k">border</span><span class="o">:</span> <span class="m">0</span><span class="p">;</span>
</span><span class='line'> <span class="k">max-width</span><span class="o">:</span> <span class="m">100</span><span class="o">%</span><span class="p">;</span>
</span><span class='line'><span class="p">}</span>
</span></code></pre></td></tr></table></div></figure>
<p><strong><em>JavaScript</em></strong> <br></p>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
<span class='line-number'>12</span>
<span class='line-number'>13</span>
<span class='line-number'>14</span>
<span class='line-number'>15</span>
<span class='line-number'>16</span>
<span class='line-number'>17</span>
<span class='line-number'>18</span>
<span class='line-number'>19</span>
<span class='line-number'>20</span>
<span class='line-number'>21</span>
<span class='line-number'>22</span>
<span class='line-number'>23</span>
<span class='line-number'>24</span>
<span class='line-number'>25</span>
<span class='line-number'>26</span>
<span class='line-number'>27</span>
<span class='line-number'>28</span>
<span class='line-number'>29</span>
<span class='line-number'>30</span>
<span class='line-number'>31</span>
<span class='line-number'>32</span>
<span class='line-number'>33</span>
<span class='line-number'>34</span>
<span class='line-number'>35</span>
<span class='line-number'>36</span>
<span class='line-number'>37</span>
<span class='line-number'>38</span>
<span class='line-number'>39</span>
<span class='line-number'>40</span>
<span class='line-number'>41</span>
<span class='line-number'>42</span>
<span class='line-number'>43</span>
</pre></td><td class='code'><pre><code class='javascript'><span class='line'><span class="o"><</span><span class="nx">script</span><span class="o">></span>
</span><span class='line'> <span class="kd">var</span> <span class="nx">cwResImg</span> <span class="o">=</span> <span class="kd">function</span> <span class="p">()</span> <span class="p">{</span>
</span><span class='line'> <span class="kd">var</span> <span class="nx">cwBpArry</span> <span class="o">=</span> <span class="p">[</span><span class="mi">1382</span><span class="p">,</span> <span class="mi">992</span><span class="p">,</span> <span class="mi">768</span><span class="p">,</span> <span class="mi">480</span><span class="p">],</span> <span class="c1">//Image breakpoint arrays</span>
</span><span class='line'> <span class="nx">currIndex</span><span class="p">,</span>
</span><span class='line'> <span class="nx">cwResImgVal</span> <span class="o">=</span> <span class="nb">Math</span><span class="p">.</span><span class="nx">max</span><span class="p">(</span><span class="nx">screen</span><span class="p">.</span><span class="nx">width</span><span class="p">,</span><span class="nx">screen</span><span class="p">.</span><span class="nx">height</span><span class="p">),</span>
</span><span class='line'> <span class="nx">hdpi</span> <span class="o">=</span> <span class="nb">window</span><span class="p">.</span><span class="nx">devicePixelRatio</span> <span class="o">></span> <span class="mi">1</span> <span class="o">?</span> <span class="nb">window</span><span class="p">.</span><span class="nx">devicePixelRatio</span> <span class="o">:</span> <span class="mi">1</span><span class="p">,</span>
</span><span class='line'> <span class="nx">rwdImgId</span> <span class="o">=</span> <span class="s2">"rwdimg-"</span><span class="o">+</span><span class="nb">Math</span><span class="p">.</span><span class="nx">floor</span><span class="p">(</span><span class="nb">Math</span><span class="p">.</span><span class="nx">random</span><span class="p">()</span><span class="o">*</span><span class="mi">1000</span><span class="p">),</span>
</span><span class='line'> <span class="nx">tpl</span><span class="o">=</span><span class="s1">'<img src="{src}" alt="{alt}" title="{title}" id="{rwdImgId}" {attributes}>'</span><span class="p">;</span>
</span><span class='line'>
</span><span class='line'> <span class="nx">cwBpArry</span><span class="p">.</span><span class="nx">push</span><span class="p">(</span><span class="nx">cwResImgVal</span><span class="p">);</span>
</span><span class='line'> <span class="nx">cwBpArry</span><span class="p">.</span><span class="nx">sort</span><span class="p">(</span><span class="kd">function</span><span class="p">(</span><span class="nx">a</span><span class="p">,</span><span class="nx">b</span><span class="p">){</span><span class="k">return</span> <span class="nx">a</span><span class="o">-</span><span class="nx">b</span><span class="p">});</span>
</span><span class='line'>
</span><span class='line'> <span class="k">if</span><span class="p">(</span><span class="nb">Array</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">indexOf</span><span class="p">){</span>
</span><span class='line'> <span class="nx">currIndex</span> <span class="o">=</span> <span class="nx">cwBpArry</span><span class="p">.</span><span class="nx">indexOf</span><span class="p">(</span><span class="nx">cwResImgVal</span><span class="p">)</span> <span class="o">+</span> <span class="mi">1</span><span class="p">;</span>
</span><span class='line'> <span class="p">}</span><span class="k">else</span><span class="p">{</span>
</span><span class='line'> <span class="k">for</span><span class="p">(</span><span class="kd">var</span> <span class="nx">i</span> <span class="k">in</span> <span class="nx">cwBpArry</span><span class="p">){</span>
</span><span class='line'> <span class="k">if</span><span class="p">(</span><span class="nx">cwBpArry</span><span class="p">[</span><span class="nx">i</span><span class="p">]</span> <span class="o">===</span> <span class="nx">cwResImgVal</span><span class="p">){</span>
</span><span class='line'> <span class="nx">currIndex</span> <span class="o">=</span> <span class="nb">parseInt</span><span class="p">(</span><span class="nx">i</span><span class="p">)</span><span class="o">+</span><span class="mi">1</span><span class="p">;</span>
</span><span class='line'> <span class="p">}</span>
</span><span class='line'> <span class="p">}</span>
</span><span class='line'> <span class="p">}</span>
</span><span class='line'>
</span><span class='line'> <span class="nx">cwBpArry</span><span class="p">[</span><span class="nx">currIndex</span><span class="p">]</span> <span class="o">=</span> <span class="nx">cwBpArry</span><span class="p">[</span><span class="nx">currIndex</span><span class="p">]</span> <span class="o">||</span> <span class="nx">cwBpArry</span><span class="p">[</span><span class="nx">currIndex</span><span class="o">-</span><span class="mi">1</span><span class="p">];</span>
</span><span class='line'>
</span><span class='line'> <span class="kd">var</span> <span class="nx">imgWid</span> <span class="o">=</span> <span class="nb">Math</span><span class="p">.</span><span class="nx">max</span><span class="p">.</span><span class="nx">apply</span><span class="p">(</span><span class="nb">Math</span><span class="p">,</span> <span class="nx">cwBpArry</span><span class="p">)</span> <span class="o"><=</span> <span class="nx">cwBpArry</span><span class="p">[</span><span class="nx">currIndex</span><span class="p">]</span> <span class="o">?</span> <span class="nx">cwBpArry</span><span class="p">[</span><span class="nx">currIndex</span><span class="o">-</span><span class="mi">2</span><span class="p">]</span> <span class="o">:</span> <span class="nx">cwBpArry</span><span class="p">[</span><span class="nx">currIndex</span><span class="p">];</span>
</span><span class='line'>
</span><span class='line'> <span class="k">return</span> <span class="p">{</span>
</span><span class='line'> <span class="nx">imgWid</span> <span class="o">:</span> <span class="nx">imgWid</span><span class="p">,</span>
</span><span class='line'> <span class="nx">hdpi</span><span class="o">:</span> <span class="nx">hdpi</span><span class="p">,</span>
</span><span class='line'> <span class="nx">id</span><span class="o">:</span><span class="nx">rwdImgId</span><span class="p">,</span>
</span><span class='line'> <span class="nx">rwdImg</span><span class="o">:</span><span class="kd">function</span><span class="p">(</span><span class="nx">arg</span><span class="p">){</span>
</span><span class='line'>
</span><span class='line'> <span class="kd">var</span> <span class="nx">src</span> <span class="o">=</span> <span class="nx">arg</span><span class="p">.</span><span class="nx">src</span> <span class="o">||</span> <span class="nx">arguments</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">||</span> <span class="s1">''</span><span class="p">,</span>
</span><span class='line'> <span class="nx">src</span> <span class="o">=</span> <span class="nx">src</span><span class="p">.</span><span class="nx">replace</span><span class="p">(</span><span class="sr">/\/s\d*\//</span><span class="p">,</span> <span class="s1">'/s'</span><span class="o">+</span><span class="nx">imgWid</span> <span class="o">*</span> <span class="nx">hdpi</span><span class="o">+</span><span class="s1">'/'</span><span class="p">),</span> <span class="c1">//picasa image size replacing (s340 to device width)</span>
</span><span class='line'> <span class="nx">title</span> <span class="o">=</span> <span class="nx">arg</span><span class="p">.</span><span class="nx">title</span> <span class="o">||</span> <span class="nx">arg</span><span class="p">.</span><span class="nx">alt</span> <span class="o">||</span> <span class="nx">arguments</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">||</span> <span class="s1">''</span><span class="p">,</span>
</span><span class='line'> <span class="nx">alt</span> <span class="o">=</span> <span class="nx">arg</span><span class="p">.</span><span class="nx">alt</span> <span class="o">||</span> <span class="nx">arg</span><span class="p">.</span><span class="nx">title</span> <span class="o">||</span> <span class="nx">arguments</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span> <span class="o">||</span> <span class="nx">arguments</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">||</span> <span class="s1">''</span><span class="p">,</span>
</span><span class='line'> <span class="nx">attributes</span> <span class="o">=</span> <span class="nx">arg</span><span class="p">.</span><span class="nx">attr</span> <span class="o">||</span> <span class="nx">arguments</span><span class="p">[</span><span class="mi">3</span><span class="p">]</span> <span class="o">||</span> <span class="s1">''</span><span class="p">,</span>
</span><span class='line'> <span class="nx">img</span> <span class="o">=</span> <span class="nx">tpl</span><span class="p">.</span><span class="nx">replace</span><span class="p">(</span><span class="s1">'{src}'</span><span class="p">,</span><span class="nx">src</span><span class="p">).</span><span class="nx">replace</span><span class="p">(</span><span class="s1">'{title}'</span><span class="p">,</span><span class="nx">title</span><span class="p">).</span><span class="nx">replace</span><span class="p">(</span><span class="s1">'{alt}'</span><span class="p">,</span><span class="nx">alt</span><span class="p">).</span><span class="nx">replace</span><span class="p">(</span><span class="s1">'{rwdImgId}'</span><span class="p">,</span><span class="nx">rwdImgId</span><span class="p">).</span><span class="nx">replace</span><span class="p">(</span><span class="s1">'{attributes}'</span><span class="p">,</span><span class="nx">attributes</span><span class="p">);</span>
</span><span class='line'> <span class="nb">document</span><span class="p">.</span><span class="nx">write</span><span class="p">(</span><span class="nx">img</span><span class="p">)</span>
</span><span class='line'> <span class="p">}</span>
</span><span class='line'> <span class="p">};</span>
</span><span class='line'><span class="p">}()</span>
</span><span class='line'><span class="o"><</span><span class="err">/script></span>
</span></code></pre></td></tr></table></div></figure>
<p>
Paste it in your page header. This will set width of the screen into ‘cwResImg’ variable. You can set image breakpoints in this variable <code>cwBpArry = [1382, 992, 768, 480];</code></p>
<p><strong><em>HTML</em></strong> <br>
Replace images in HTML with.</p>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
</pre></td><td class='code'><pre><code class='html'><span class='line'><span class="nt"><noscript></span>
</span><span class='line'> <span class="nt"><img</span> <span class="na">src=</span><span class="s">"http://lh6.googleusercontent.com/-nI33VLdtmFo/UN9MmPN6bHI/AAAAAAAAFEE/1uJBJ7-plEs/s720/Webpagetest-IE8-Octopress-Default-waterfall.png"</span> <span class="na">alt=</span><span class="s">"Responsive images test"</span><span class="nt">></span>
</span><span class='line'><span class="nt"></noscript></span>
</span><span class='line'><span class="nt"><script></span>
</span><span class='line'> <span class="nx">cwResImg</span><span class="p">.</span><span class="nx">rwdImg</span><span class="p">(</span><span class="s2">"http://lh6.googleusercontent.com/-nI33VLdtmFo/UN9MmPN6bHI/AAAAAAAAFEE/1uJBJ7-plEs/s450/Webpagetest-IE8-Octopress-Default-waterfall.png"</span><span class="p">,</span> <span class="s1">'Responsive images text script'</span><span class="p">);</span>
</span><span class='line'>
</span><span class='line'> <span class="o">---</span><span class="nx">or</span><span class="o">----</span>
</span><span class='line'>
</span><span class='line'> <span class="nx">cwResImg</span><span class="p">.</span><span class="nx">rwdImg</span><span class="p">({</span><span class="nx">src</span><span class="o">:</span><span class="s1">'http://lh6.googleusercontent.com/-nI33VLdtmFo/UN9MmPN6bHI/AAAAAAAAFEE/1uJBJ7-plEs/s450/Webpagetest-IE8-Octopress-Default-waterfall.png'</span><span class="p">,</span> <span class="nx">alt</span><span class="o">:</span><span class="s1">'Responsive images text script'</span><span class="p">,</span> <span class="nx">title</span><span class="o">:</span><span class="s1">'Responsive images text script'</span><span class="p">});</span>
</span><span class='line'><span class="nt"></script></span>
</span></code></pre></td></tr></table></div></figure>
<p>It has two parts <br>
1) noscript tag contains a standard image for fallback. If js is not supported, this image will show.</p>
<p>2) Script part <br>
Syntax</p>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
</pre></td><td class='code'><pre><code class='javascript'><span class='line'><span class="nx">cwResImg</span><span class="p">.</span><span class="nx">rwdImg</span><span class="p">(</span><span class="s2">"src"</span><span class="p">,</span><span class="s2">"alt"</span><span class="p">,</span><span class="s2">"title"</span><span class="p">,</span><span class="s2">"class='myclass'"</span><span class="p">);</span>
</span><span class='line'><span class="nx">or</span>
</span><span class='line'><span class="nx">cwResImg</span><span class="p">.</span><span class="nx">rwdImg</span><span class="p">({</span><span class="nx">src</span><span class="o">:</span><span class="s2">"src"</span><span class="p">,</span> <span class="nx">alt</span><span class="o">:</span><span class="s2">"alt"</span><span class="p">,</span><span class="nx">title</span><span class="o">:</span><span class="s2">"title"</span><span class="p">,</span><span class="nx">attr</span><span class="o">:</span><span class="s2">"class='myclass'"</span><span class="p">})</span>
</span></code></pre></td></tr></table></div></figure>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class='javascript'><span class='line'><span class="nx">cwResImg</span><span class="p">.</span><span class="nx">rwdImg</span><span class="p">(</span><span class="s2">"http://lh6.googleusercontent.com/-nI33VLdtmFo/UN9MmPN6bHI/AAAAAAAAFEE/1uJBJ7-plEs/s450/Webpagetest-IE8-Octopress-Default-waterfall.png"</span><span class="p">,</span><span class="s2">"Responsive images text script"</span><span class="p">,</span><span class="s2">"Responsive images text script"</span><span class="p">);</span>
</span></code></pre></td></tr></table></div></figure>
<p>JavaScript variable ‘cwResImg’ will replace by the max width of the device.</p>
<p>When page loads url will be like the following, if its a desktop with resolution more than 1382px</p>
<p>//lh6.googleusercontent.com/-IdiwvKGQ8Lk/UN9KOZvdW7I/AAAAAAAAFDk/iSvy1_SZrrM/<strong>s1382</strong>/RTT%2520Decodize%2520github.png</p>
<h3>Demo</h3>
<p><a href="http://demos.decodize.com/responsive-images/demo.html" title="Responsive images" target="_blank">Responsive images</a></p>
<h3>Performance and Bandwidth</h3>
<p>After including this there is a noticeable performance improvement in iPhone waterfall view.</p>
<p>Before (11.866s) <br>
<noscript>
<img src="//lh6.googleusercontent.com/-VQbJXZuyy2g/UOXNzTDn7EI/AAAAAAAAFGY/4WE49NLo3Os/s800/Before%2520responsive%2520image.jpg" alt="Before responsive image" title="Before responsive image">
</noscript><script>
cwResImg.rwdImg("//lh6.googleusercontent.com/-VQbJXZuyy2g/UOXNzTDn7EI/AAAAAAAAFGY/4WE49NLo3Os/s800/Before%2520responsive%2520image.jpg","Before responsive image");
</script></p>
<p>After (8.841s) <br>
<noscript>
<img src="//lh5.googleusercontent.com/-M18BajmhKdE/UOXNzNWfpvI/AAAAAAAAFGU/RIjb8u81HeI/s800/After%2520responsive%2520image.jpg" alt="After responsive image" title="After responsive image">
</noscript><script>
cwResImg.rwdImg("//lh5.googleusercontent.com/-M18BajmhKdE/UOXNzNWfpvI/AAAAAAAAFGU/RIjb8u81HeI/s800/After%2520responsive%2520image.jpg","After responsive image");
</script></p>
<p><strong><em>Drawbacks</em></strong> <br>
Messy HTML. <br>
Accessibility</p>
</div>
<footer>
<p class="meta">
<span class="byline author vcard">Posted by <span class="fn">Praveen Vijayan</span></span>
<time datetime="2013-01-04T00:19:00+05:30" pubdate data-updated="true">Jan 4<span>th</span>, 2013</time>
<span class="categories">
<a class='category' href='/blog/categories/html/'>html</a>
</span>
</p>
<div class="sharing">
<a href="http://twitter.com/share" class="twitter-share-button" data-url="http://decodize.com/html/simple-responsive-image-technique/" data-via="praveen_vijaya" data-counturl="http://decodize.com/html/simple-responsive-image-technique/" >Tweet</a>
<div class="g-plusone" data-size="medium"></div>
<div class="fb-like" data-send="true" data-width="450" data-show-faces="false"></div>
</div>
<p class="meta">
<a class="basic-alignment left" href="/html/moving-from-wordpress-to-octopress/" title="Previous Post: Moving from Wordpress to Octopress redesign notes">« Moving from Wordpress to Octopress redesign notes</a>
<a class="basic-alignment right" href="/html/slidemote-universal-remote-control-for-html5-presentations/" title="Next Post: Slidemote - Universal remote control for html5 presentations">Slidemote - Universal remote control for html5 presentations »</a>
</p>
</footer>
</article>
<section>
<h1>Comments</h1>
<div id="disqus_thread" aria-live="polite"><noscript>Please enable JavaScript to view the <a href="http://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
</div>
</section>
</div>
<aside class="sidebar">
<section>
<h1>Recent Posts</h1>
<ul id="recent_posts">
<li class="post">
<a href="/html,css,javascript,/gruntjs,/yo,/bower/front-end-viewpoints-architecture-building-large-websites/">Tooling for modern web app development</a>
</li>
<li class="post">
<a href="/GAE/linktomob-share-your-links-quickly-and-easily-on-mobile-devices/">Linktomob - Share your links quickly and easily on mobile devices.</a>
</li>
<li class="post">
<a href="/html/getting-started-with-yeoman-1-dot-0-beta-on-windows/">Getting started with Yeoman 1.0 Beta on Windows</a>
</li>
<li class="post">
<a href="/html/slidemote-universal-remote-control-for-html5-presentations/">Slidemote - Universal remote control for html5 presentations</a>
</li>
<li class="post">
<a href="/html/simple-responsive-image-technique/">Simple Responsive image technique</a>
</li>
</ul>
</section>
<section>
<h1>Latest Tweets</h1>
<ul id="tweets">
<li class="loading">Status updating...</li>
</ul>
<script>
(function(w, d, s) {
function go(){
var js, fjs = d.getElementsByTagName(s)[0], load = function(url, id) {
if (d.getElementById(id)) {return;}
js = d.createElement(s); js.src = url; js.id = id; js.async = true;
$(js).load(function(){
getTwitterFeed("praveen_vijaya", 4, false);
});
fjs.parentNode.insertBefore(js, fjs);
};
load('/javascripts/twitter.js', 'recentTweets');
}
if (w.addEventListener) { w.addEventListener("load", go, false); }
else if (w.attachEvent) { w.attachEvent("onload",go); }
}(window, document, 'script'));
</script>
<a href="http://twitter.com/praveen_vijaya" class="twitter-follow-button" data-show-count="false">Follow @praveen_vijaya</a>
</section>
<section class="googleplus">
<h1>
<a href="https://plus.google.com/111067440252423767432?rel=author">
<img src="http://www.google.com/images/icons/ui/gprofile_button-32.png" width="32" height="32">
Google+
</a>
</h1>
</section>
</aside>
</div>
</div>
<footer role="contentinfo"><p>
Copyright © 2013 - 2014 Praveen Vijayan -
<span class="credit">Powered by <a href="http://octopress.org">Octopress</a><a href="https://plus.google.com/112271602152550681222" rel="publisher" style="visibility: hidden">Google+</a></span>
</p>
</footer>
<script type="text/javascript">
var disqus_shortname = 'decodize';
// var disqus_developer = 1;
var disqus_identifier = 'http://decodize.com/html/simple-responsive-image-technique/';
var disqus_url = 'http://decodize.com/html/simple-responsive-image-technique/';
var disqus_script = 'embed.js';
(function(w, d, s) {
function go(){
var js, fjs = d.getElementsByTagName(s)[0], load = function(url, id) {
if (d.getElementById(id)) {return;}
js = d.createElement(s); js.src = url; js.id = id; js.async = true;
fjs.parentNode.insertBefore(js, fjs);
};
load('http://' + disqus_shortname + '.disqus.com/' + disqus_script, 'discuss');
}
if (w.addEventListener) { w.addEventListener("load", go, false); }
else if (w.attachEvent) { w.attachEvent("onload",go); }
}(window, document, 'script'));
</script>
<div id="fb-root"></div>
<script>
(function(w, d, s) {
function go(){
var js, fjs = d.getElementsByTagName(s)[0], load = function(url, id) {
if (d.getElementById(id)) {return;}
js = d.createElement(s); js.src = url; js.id = id; js.async = true;
fjs.parentNode.insertBefore(js, fjs);
};
load('//connect.facebook.net/en_US/all.js#appId=212934732101925&xfbml=1', 'facebook-jssdk');
}
if (w.addEventListener) { w.addEventListener("load", go, false); }
else if (w.attachEvent) { w.attachEvent("onload",go); }
}(window, document, 'script'));
</script>
<script>
(function(w, d, s) {
function go(){
var js, fjs = d.getElementsByTagName(s)[0], load = function(url, id) {
if (d.getElementById(id)) {return;}
js = d.createElement(s); js.src = url; js.id = id; js.async = true;
fjs.parentNode.insertBefore(js, fjs);
};
load('https://apis.google.com/js/plusone.js', 'gplus1js');
}
if (w.addEventListener) { w.addEventListener("load", go, false); }
else if (w.attachEvent) { w.attachEvent("onload",go); }
}(window, document, 'script'));
</script>
<script>
(function(w, d, s) {
function go(){
var js, fjs = d.getElementsByTagName(s)[0], load = function(url, id) {
if (d.getElementById(id)) {return;}
js = d.createElement(s); js.src = url; js.id = id; js.async = true;
fjs.parentNode.insertBefore(js, fjs);
};
load('http://platform.twitter.com/widgets.js', 'twitterwid');
}
if (w.addEventListener) { w.addEventListener("load", go, false); }
else if (w.attachEvent) { w.attachEvent("onload",go); }
}(window, document, 'script'));
</script>
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-12969780-1']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
<script type="text/javascript">
var GoSquared = {};
GoSquared.acct = "GSN-491671-U";
(function(w){
function gs(){
w._gstc_lt = +new Date;
var d = document, g = d.createElement("script");
g.type = "text/javascript";
g.src = "//d1l6p2sc9645hc.cloudfront.net/tracker.js";
var s = d.getElementsByTagName("script")[0];
s.parentNode.insertBefore(g, s);
}
w.addEventListener ?
w.addEventListener("load", gs, false) :
w.attachEvent("onload", gs);
})(window);
</script>
<script type="text/javascript">
var analytics=analytics||[];analytics.load=function(e){var t=document.createElement("script");t.type="text/javascript",t.async=!0,t.src=("https:"===document.location.protocol?"https://":"http://")+"d2dq2ahtl5zl1z.cloudfront.net/analytics.js/v1/"+e+"/analytics.min.js";var n=document.getElementsByTagName("script")[0];n.parentNode.insertBefore(t,n);var r=function(e){return function(){analytics.push([e].concat(Array.prototype.slice.call(arguments,0)))}},i=["identify","track","trackLink","trackForm","trackClick","trackSubmit","pageview","ab","alias","ready"];for(var s=0;s<i.length;s++)analytics[i[s]]=r(i[s])};
analytics.load("4rv3y0wzxl");
</script>
</body>
</html>