Episode 15: Adaptive Images and Responsive SVGs
The Treehouse Show Episode 15: Adaptive Images and Responsive SVGs
Teacher Notes
Video Transcript
-
00:00
[The Treehouse Show]
-
00:02
Hi, I'm Nick Pettit. >>I'm Jason Seifer.
-
00:04
[Pettit] And you're watching The Treehouse Show, your weekly dose of Internet,
-
00:07
where we talk about all things web design, web development, and more.
-
00:11
[Seifer] In this episode, we'll be talking about responsive image techniques,
-
00:15
controlling and customizing your development environment, and more.
-
00:19
[Pettit] Let's check it out!
-
00:21
[The Treehouse Show]
-
00:27
First up is adaptive images, available at adaptive-images.com.
-
00:33
On the show, I feel like we've talked about responsive web design
-
00:37
every single episode, but it's because it's important.
-
00:40
And adaptive images makes it even easier.
-
00:43
Basically, when a visitor comes to your website,
-
00:46
it will detect the screen size, automatically create a rescaled image,
-
00:51
and then cache it so that when the next visitor comes by,
-
00:55
that image will be ready to go.
-
00:59
It uses a PHP script and hooks into Apache,
-
01:04
and it's actually pretty clever in its implementation.
-
01:07
But the bottom line is, it will create smaller images
-
01:11
that are more appropriately scaled in terms of their file size to smaller mobile devices.
-
01:17
[Seifer] So this is going to save time, say, if you're on an iPhone or a mobile device.
-
01:22
You're going to get a smaller image and thus the page is going to load quicker,
-
01:25
which is good for everybody, I think, in that scenario, right?
-
01:29
[Pettit] Exactly. And as it says on the site,
-
01:33
your site is being viewed by increasingly smaller, slower,
-
01:37
and low bandwidth devices.
-
01:40
[Seifer] That's good news. >>Yeah. That's great.
-
01:43
[Seifer] Awesome. >>All right.
-
01:45
[Seifer] So along those lines, and completely not along those lines,
-
01:48
next up is Snappy Dashboards with Redis.
-
01:52
Now, Nick, you've probably seen applications where you log into the app
-
01:56
and it has a dashboard overview of what's going on,
-
01:58
maybe how many clicks were someplace, or a bar graph of what's going on. >>Exactly.
-
02:04
[Seifer] Well, it can occasionally be very cumbersome
-
02:07
to get at that data if you're using a relational database.
-
02:10
This could take a lot of different queries to see the proper information,
-
02:15
and it can wind up becoming a little bit expensive.
-
02:18
[Pettit] Because you have to pull together all these various pieces of information.
-
02:22
[Seifer] Yeah. You have to assemble a whole bunch.
-
02:23
So there's an interesting blog post called "Snappy Dashboards with Redis."
-
02:29
Now, this talks about using Redis, which is one of these
-
02:32
newfangled, NoSQL databases. >>Whoa. >>I know.
-
02:37
A lot of words there. A lot of words.
-
02:40
But what Redis does is, essentially, it's like a glorified key value store that's persistent.
-
02:45
So the technique that they use in this post is concatenating
-
02:50
all your different statistics with certain Redis keys
-
02:53
that are going to be a lot quicker to increment and decrement.
-
02:57
This way, when you want to create a dashboard,
-
02:59
you only have to do a limited amount of querying
-
03:02
from Redis rather than your database.
-
03:05
This is going to result in a lot quicker page use for your users.
-
03:09
The blog post has more specific techniques on how they wound up doing this,
-
03:13
and the different keys that they wound up using,
-
03:17
and even some sample Ruby code in order to do this.
-
03:20
This is definitely something that you're going to want to
-
03:23
read the show notes for for more information,
-
03:25
and you can find the show notes on our YouTube channel
-
03:28
at youtube.com/gotreehouse.
-
03:31
[Pettit] All right. Go treehouse. So next up,
-
03:34
we're going to talk about how to create a responsive SVG.
-
03:39
[Seifer] Now, is it true that people are pronounicing SVG as "savage?"
-
03:42
[Pettit] No. I think that's actually just you, Jason.
-
03:45
[Seifer] Thought I read that somewhere. >>Nope.
-
03:47
You just made that up. All right.
-
03:51
Actually, we're not going to tell you how to do it, we're going to direct you
-
03:53
to this really great blog post that tells you exactly how to do it.
-
03:57
And actually, it's very simple.
-
04:00
It's very simple to creating a fluid image.
-
04:03
Basically, you would create your vector image in Illustrator,
-
04:09
and you want to go ahead and export it as an SVG.
-
04:12
I am kind of glossing over this a little bit,
-
04:16
but ultimately, you'll end up with some HTML that is your SVG,
-
04:21
and you can put that into your HTML document, I should say.
-
04:26
Then, in your CSS, you can go ahead and set the width to 100%.
-
04:33
That's very similar to what you would do for images in a responsive website.
-
04:38
What this is going to do is it's going to cause the SVG
-
04:41
to take up the full width of its parent element,
-
04:44
and that way, if you're resizing the browser in a fluid layout,
-
04:51
it will go ahead and just continue to expand or contract proportionally.
-
04:58
Pretty nifty, and again, it's very similar to fluid images,
-
05:02
but it's something that, I don't know, I wouldn't have known that had I not read it.
-
05:08
[Seifer] I'm pretty sure it's pronounced "savages."
-
05:11
[Pettit] I think you're right, Jason. I'll let you go on thinking that.
-
05:14
[Seifer] Thanks. Next up is our app review.
-
05:18
[Pettit] Let's check it out.
-
05:22
[App Review]
-
05:26
[Seifer] Our app review this week is an app called Shortcat.
-
05:29
[Pettit] And that has nothing to do with Longcat. >>Except it's the opposite. >>Got it.
-
05:34
[Seifer] Shortcat is a very interesting application for OS X.
-
05:38
And this is going to give you the ability to interface with GUI elements using the keyboard.
-
05:46
Now, I know that's a little bit strange to say,
-
05:48
but you get a command prompt, and--yeah, here we go.
-
05:52
Cut to it. You'll notice this little video they have on the site in system preferences.
-
05:57
[Pettit] I only notice the really cute cat.
-
05:59
[Seifer]. Yeah, look at that. Look at that cat.
-
06:01
It's got a little computer mouse hanging from its mouth.
-
06:04
[Pettit] That's crazy. >>I know.
-
06:08
So the example that they give is in system preferences,
-
06:10
and if you wanted to go to the network preference,
-
06:13
you do the Shortcat shortcut, and press the letter 'n' for network.
-
06:20
Then you can completely navigate around the OS X GUI using Shortcat.
-
06:26
What I found that's really interesting is it works with Chrome as well.
-
06:31
So let me see if I can get my navigation bar up here
-
06:33
So I launch Shortcat with command + shift + space.
-
06:37
You see the little cat eyes come up on the bottom of the screen,
-
06:40
and if I wanted to access the Chrome menu, I could type 'c,'
-
06:44
and you can see in the top right corner of the screen it gets highlighted in green,
-
06:48
press enter, and it shows you what's going on.
-
06:51
[Pettit] Huh. That's pretty cool. >>Really, really good app.
-
06:54
Saves a lot of time.
-
06:57
Well, you know. Gives you a lot of shortcuts with Shortcat.
-
07:00
[Pettit] And, you know, shortcuts are actually one of those interesting things
-
07:03
that, they never seem like they're going to save a lot of time,
-
07:06
but actually moving your mouse around the screen, as lazy as this sounds,
-
07:12
it does take a lot of time to click on small, little buttons.
-
07:16
So anything that you can do with the keyboard is probably going to speed up your workflow.
-
07:21
In fact, Jason introduced me to Gmail shortcuts in 2012.
-
07:27
[Seifer] I don't know how you lived. >>I didn't, Jason. Not until now.
-
07:30
[Seifer] You weren't really living. >>Exactly.
-
07:33
So next up is Enquire.js, which is available at this really long URL
-
07:40
which will be in the lower third.
-
07:42
Basically, Enquire.js is a way for you to include media queries in JavaScript.
-
07:51
[Seifer] So that's what it does. Inquiring minds wanted to know. >>Huh. >>Huh. >>Okay, enough.
-
08:00
This sounds a little bit crazy, and that might be what you're inquiring about, Jason.
-
08:06
Including media queries in your JavaScript sounds a little strange, right?
-
08:10
You normally include media queries in your CSS.
-
08:14
When you're creating a responsive design,
-
08:17
you want to go ahead and create your fluid grid,
-
08:20
and then as that starts to break down towards
-
08:23
smaller and smaller or larger and larger screen sizes,
-
08:26
you use media queries to apply different CSS to change the layout.
-
08:32
Now, in JavaScript, you can actually do something very similar,
-
08:37
but instead of applying different styling,
-
08:40
Enquire.js allows you to apply different JavaScript.
-
08:45
So as you start to get towards a larger screen size or a smaller screen size,
-
08:50
there might be different functions that you want to use
-
08:54
or different pieces of JavaScript entirely.
-
08:58
And you don't necessarily need it in other types of layouts.
-
09:02
So that's pretty handy, because it's probably going to end up
-
09:04
saving you CPU cycles when you're not executing different pieces of code.
-
09:10
So it's pretty nifty. >>I think it'll also clean up your code quite a bit,
-
09:13
whereas rather than hooking in to the window resize event
-
09:16
and checking the width and duplicating all of that,
-
09:19
just put in the media query. >>Yeah, exactly.
-
09:22
And the nice thing about it is it's super, super tiny.
-
09:25
I think it's only like a kilobyte or less, something like that.
-
09:30
And it doesn't have any dependencies, so you don't need jQuery.
-
09:34
You can just go ahead and use Enquire.js in your next web project
-
09:38
and enjoy blissful JavaScript goodness.
-
09:43
[Seifer] That, I think, is the show title.
-
09:45
"Blissful JavaScript Goodness." >>Got it.
-
09:48
[Seifer] Next up, there is a great blog post over on the NetTuts blog
-
09:52
on how to customize your command prompt.
-
09:55
As you may have been able to tell with the Shortcat review,
-
09:58
I really like knowing exactly what's going on on my system
-
10:02
and having shortcuts going around.
-
10:05
So if you're working in the terminal a lot,
-
10:08
this blog post will show you what you can do to customize different parts of it.
-
10:12
So if you want to see what Git branch you're on
-
10:15
or what directory you're currently in,
-
10:18
as well as the name of your computer, in this case, Mothership.
-
10:21
That's an okay name; I don't know if I'm totally sold.
-
10:23
I would probably go with something different, like Battlestar.
-
10:28
So this is just a really thorough blog post on how to go through
-
10:31
and customize your command prompt as well as some other tips
-
10:34
on maybe using a different command prompt or command shell.
-
10:38
So check that out. We'll have that in the show notes as well,
-
10:41
which is on our YouTube channel.
-
10:43
[Pettit] At youtube.com/gotreehouse. >>Yes.
-
10:46
[Pettit] Thank you. All right, next up is Grid-A-Licious,
-
10:50
and this is a really, really cool project
-
10:53
that's actually been around for quite some time.
-
10:56
It's been around since 2008. >>So why are we talking about it now?
-
11:00
[Pettit] Well, Jason, because it's still relevant.
-
11:02
I'm just going to go ahead and click around a little bit here.
-
11:06
So if I go ahead and click on these small little icons
-
11:10
that represent various device screen sizes,
-
11:14
you can see how Grid-A-Licious responds to those sizes.
-
11:20
[Seifer] Oh, it looks like it reflows your grid. >>Exactly.
-
11:23
Now-- >>That's delicious!
-
11:25
[Pettit] If I go ahead and scroll down here,
-
11:28
you can see that the cool thing about Grid-A-Licious
-
11:30
is that it compacts all of those different little divs, or boxes, into a smaller space.
-
11:41
Because sometimes when you have a row of elements that are different heights,
-
11:46
you'll get some weird spacing when you go down to the next row,
-
11:49
because if an element is really short and it's next to a really tall element,
-
11:54
you'll still have all of that space below the shorter one.
-
11:58
But the nice thing about Grid-A-Licious is that it compacts all those and sticks them all together.
-
12:04
So if you've ever checked out, say, Pinterest, this is kind of the layout that they have.
-
12:08
It's all sort of squished together. >>Oh, nice.
-
12:12
So they can recreate Pinterest. >>Exactly.
-
12:15
If you're looking to recreate Pinterest, this would be a great way to get started.
-
12:20
Now, in these examples you can go ahead and see what happens
-
12:23
when you append various elements, and they're randomly sized.
-
12:28
You can also prepend rows, and you can see how those might get filled in.
-
12:33
So it's pretty nifty, and, of course, this has been around a while,
-
12:37
but the thing that's new about it is that it's now responsive,
-
12:41
which is-- >>A thing. >>It's a thing.
-
12:44
It's pretty important. >>I guess. >>Yeah.
-
12:48
[Seifer] That's a cool project. >>Yeah, very cool.
-
12:50
I'm really pretty impressed by it.
-
12:52
[Seifer] It's delicious. >>Love it.
-
12:59
[Seifer] All right. Well, I think that's about out of time for us.
-
13:01
[Pettit] Jason, what did we learn today?
-
13:03
[Seifer] We learned that we're actually moving backwards in web time.
-
13:07
[Pettit] It's true. Screens are getting smaller, devices are getting slower,
-
13:11
and there's less and less bandwidth all the time.
-
13:14
Eventually, we're going to end up at a singularity,
-
13:16
where there's just no Internet at all.
-
13:19
[Seifer] I do not look forward to that day. >>Yeah.
-
13:21
I think it's the end of 2012, from what I've heard. >>Uh-oh.
-
13:23
Wow. I've got some emails to send and some web browsing to do.
-
13:28
So who are you on Twitter? >>I'm @NICKRP.
-
13:31
[Seifer] And I am @JSEIFER. We want to thank you so much
-
13:33
for tuning in to this episode of The Treehouse Show.
-
13:36
For show notes and more, check out our YouTube channel at youtube.com/gotreehouse.
-
13:41
[Pettit] And, of course, if you'd like to check out more videos like this one,
-
13:45
and learn about web design, web development, iOS, Android, and business,
-
13:49
be sure to check us out at teamtreehouse.com.
-
13:52
That's it for this week, and thank you so much for watching.
-
13:58
[The Treehouse Show]