Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:00,005 --> 00:00:03,003
- In the last two videos, I showed you the source set
2
00:00:03,003 --> 00:00:06,001
in sizes attribute for the image element
3
00:00:06,001 --> 00:00:09,002
and how they could be used to provide multiple image files
4
00:00:09,002 --> 00:00:11,003
to the browser and let it decide
5
00:00:11,003 --> 00:00:13,008
which one to load and display.
6
00:00:13,008 --> 00:00:17,000
In all of those examples, the image itself,
7
00:00:17,000 --> 00:00:20,002
the photo of a dog was the same photograph.
8
00:00:20,002 --> 00:00:23,007
It'd been saved as many different copies with more pixels
9
00:00:23,007 --> 00:00:27,004
or fewer pixels, but the content in the photo was the same
10
00:00:27,004 --> 00:00:29,001
the whole entire time.
11
00:00:29,001 --> 00:00:32,000
The way it was cropped, its aspect ratio.
12
00:00:32,000 --> 00:00:34,006
But what if we want to do more than swap out
13
00:00:34,006 --> 00:00:37,005
a low-res file for a high-res file?
14
00:00:37,005 --> 00:00:40,009
What if we want to use a different image on a small screen
15
00:00:40,009 --> 00:00:42,005
versus a big screen?
16
00:00:42,005 --> 00:00:45,007
Maybe we want the image to be tall and narrow on mobile
17
00:00:45,007 --> 00:00:48,002
where it's short and wide on desktop.
18
00:00:48,002 --> 00:00:52,001
Or even use a completely different photo altogether.
19
00:00:52,001 --> 00:00:54,003
Let's look at another example.
20
00:00:54,003 --> 00:00:57,003
How about for this photo, on big screens,
21
00:00:57,003 --> 00:01:01,000
will show some of the field and her whole body,
22
00:01:01,000 --> 00:01:05,003
but on small screens, will crop in and focus on her face?
23
00:01:05,003 --> 00:01:08,008
The image element alone, even with the source set
24
00:01:08,008 --> 00:01:11,006
or sizes attributes, can't do this.
25
00:01:11,006 --> 00:01:15,002
For this, we use the picture element.
26
00:01:15,002 --> 00:01:18,003
We'll start with the good old image element as always
27
00:01:18,003 --> 00:01:21,007
with the alt text and a URL to a file that will be used
28
00:01:21,007 --> 00:01:24,007
by any browser that doesn't understand the picture element.
29
00:01:24,007 --> 00:01:27,002
Like Internet Explorer 11.
30
00:01:27,002 --> 00:01:29,005
Even if you don't care about old browsers,
31
00:01:29,005 --> 00:01:32,003
you still have to have an image element.
32
00:01:32,003 --> 00:01:35,008
If you leave it out, none of this is going to work.
33
00:01:35,008 --> 00:01:40,007
Then, let's wrap this image element with a picture element.
34
00:01:40,007 --> 00:01:43,001
Now that we have a wrapper for the whole thing,
35
00:01:43,001 --> 00:01:48,000
we can list alternative options through the sources element.
36
00:01:48,000 --> 00:01:50,003
I want to provide two options,
37
00:01:50,003 --> 00:01:53,003
so I'll create two source elements.
38
00:01:53,003 --> 00:01:55,008
First, let's point to an image file
39
00:01:55,008 --> 00:01:59,006
with the source set attribute on the sources element.
40
00:01:59,006 --> 00:02:02,005
Here, we'll pick our mobile image
41
00:02:02,005 --> 00:02:06,009
at the cropped version of the photo at 320 pixels wide.
42
00:02:06,009 --> 00:02:10,001
Now, let's put a kind of media query
43
00:02:10,001 --> 00:02:13,004
in the other source element and point that
44
00:02:13,004 --> 00:02:16,004
to an image that we want to use on bigger screens.
45
00:02:16,004 --> 00:02:18,009
When the viewport is a minimum of 600,
46
00:02:18,009 --> 00:02:22,002
600 hundred pixels wide or bigger,
47
00:02:22,002 --> 00:02:25,001
the landscape version of this photo loads.
48
00:02:25,001 --> 00:02:27,007
When the viewport is smaller than 600 pixels,
49
00:02:27,007 --> 00:02:30,000
the cropped version loads.
50
00:02:30,000 --> 00:02:32,000
It's pretty fantastic.
51
00:02:32,000 --> 00:02:34,008
Now you notice, we're using source set
52
00:02:34,008 --> 00:02:36,009
on the sources element.
53
00:02:36,009 --> 00:02:40,005
It works exactly the same way it does on the image element.
54
00:02:40,005 --> 00:02:42,005
Which means we can take everything that we learned
55
00:02:42,005 --> 00:02:45,006
from the last two videos and apply it here.
56
00:02:45,006 --> 00:02:49,002
In this demo, I combined multiple techniques
57
00:02:49,002 --> 00:02:52,004
using picture, source, source set
58
00:02:52,004 --> 00:02:55,007
and providing multiple file options in each source set
59
00:02:55,007 --> 00:02:59,000
telling the browser how wide each file is.
60
00:02:59,000 --> 00:03:02,003
The browser swaps from one file to another
61
00:03:02,003 --> 00:03:04,009
only using the bigger files when they're needed.
62
00:03:04,009 --> 00:03:07,004
It's taking both the viewport size
63
00:03:07,004 --> 00:03:09,005
and the retina screen into account.
64
00:03:09,005 --> 00:03:11,009
Then when the viewport becomes 600 pixels wide,
65
00:03:11,009 --> 00:03:15,009
it switches from the cropped version to the wide version.
66
00:03:15,009 --> 00:03:18,006
Of course, because I keep changing the viewport
67
00:03:18,006 --> 00:03:22,000
as I'm showing you this demo, this browser is downloading
68
00:03:22,000 --> 00:03:23,004
all of these different files.
69
00:03:23,004 --> 00:03:26,005
And that's not the point of this HTML.
70
00:03:26,005 --> 00:03:29,001
Normally, a person is looking at a web page
71
00:03:29,001 --> 00:03:30,009
through one screen.
72
00:03:30,009 --> 00:03:33,002
Their viewport is staying one size
73
00:03:33,002 --> 00:03:35,007
and they just get the one image file.
74
00:03:35,007 --> 00:03:37,007
The one that's best for them.
75
00:03:37,007 --> 00:03:39,006
None of the rest of the files are downloaded.
76
00:03:39,006 --> 00:03:43,009
Which is the whole point to save on downloads.
77
00:03:43,009 --> 00:03:46,001
HTML gives us a powerful set of options
78
00:03:46,001 --> 00:03:48,004
for optimizing images on the web.
79
00:03:48,004 --> 00:03:51,002
So we can send the smallest file possible
80
00:03:51,002 --> 00:03:54,000
while still publishing gorgeous images
81
00:03:54,000 --> 00:03:57,004
that are sometimes displayed quite large.
82
00:03:57,004 --> 00:03:59,005
Now, you might be thinking,
83
00:03:59,005 --> 00:04:01,005
wow that's a lot of files to create.
84
00:04:01,005 --> 00:04:03,000
There's a lot of math involved
85
00:04:03,000 --> 00:04:04,007
in figuring out all these numbers.
86
00:04:04,007 --> 00:04:06,005
Yeah.
87
00:04:06,005 --> 00:04:09,006
On most sites though, the work needed to publish each image
88
00:04:09,006 --> 00:04:12,000
in this way is automated.
89
00:04:12,000 --> 00:04:14,003
A person who adds content to the site
90
00:04:14,003 --> 00:04:17,005
just uploads one large image.
91
00:04:17,005 --> 00:04:21,000
And then magical robots on the server do all the work
92
00:04:21,000 --> 00:04:24,006
of creating the image files and writing out all the code.
93
00:04:24,006 --> 00:04:27,006
Those magical robots do need to be told what to do of course
94
00:04:27,006 --> 00:04:29,001
and perhaps, that will be your job,
95
00:04:29,001 --> 00:04:33,001
to figure out how this should work for your team's website.
96
00:04:33,001 --> 00:04:35,008
And then, you set it up for everyone else.
97
00:04:35,008 --> 00:04:38,004
It's definitely worth doing.
98
00:04:38,004 --> 00:04:41,003
The image files for this demo range in size
99
00:04:41,003 --> 00:04:45,009
from 27k to 593k.
100
00:04:45,009 --> 00:04:50,006
That's half a megabyte difference per photo.
101
00:04:50,006 --> 00:04:53,004
If we created a web page that has six photos on it,
102
00:04:53,004 --> 00:04:57,003
and save our users 500k per photo,
103
00:04:57,003 --> 00:05:00,008
that's three megabytes of data we've saved.
104
00:05:00,008 --> 00:05:03,006
Definitely worth doing.
105
00:05:03,006 --> 00:05:06,009
If you want to learn more about how to use this HTML,
106
00:05:06,009 --> 00:05:09,004
there's another course on responsive images
107
00:05:09,004 --> 00:05:13,000
that goes even deeper into the details.
8157
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.