Episode 15: Adaptive Images and Responsive SVGs


In this episode of The Treehouse Show, Nick Pettit (@nickrp) and Jason Seifer (@jseifer) talk about Adaptive Images, Snappy Dashboards, and more.

Video Transcript

  • 0:00

    [The Treehouse Show]

  • 0:02

    Hi, I'm Nick Pettit. >>I'm Jason Seifer.

  • 0:04

    [Pettit] And you're watching The Treehouse Show, your weekly dose of Internet,

  • 0:07

    where we talk about all things web design, web development, and more.

  • 0:11

    [Seifer] In this episode, we'll be talking about responsive image techniques,

  • 0:15

    controlling and customizing your development environment, and more.

  • 0:19

    [Pettit] Let's check it out!

  • 0:21

    [The Treehouse Show]

  • 0:27

    First up is adaptive images, available at adaptive-images.com.

  • 0:33

    On the show, I feel like we've talked about responsive web design

  • 0:37

    every single episode, but it's because it's important.

  • 0:40

    And adaptive images makes it even easier.

  • 0:43

    Basically, when a visitor comes to your website,

  • 0:46

    it will detect the screen size, automatically create a rescaled image,

  • 0:51

    and then cache it so that when the next visitor comes by,

  • 0:55

    that image will be ready to go.

  • 0:59

    It uses a PHP script and hooks into Apache,

  • 1:04

    and it's actually pretty clever in its implementation.

  • 1:07

    But the bottom line is, it will create smaller images

  • 1:11

    that are more appropriately scaled in terms of their file size to smaller mobile devices.

  • 1:17

    [Seifer] So this is going to save time, say, if you're on an iPhone or a mobile device.

  • 1:22

    You're going to get a smaller image and thus the page is going to load quicker,

  • 1:25

    which is good for everybody, I think, in that scenario, right?

  • 1:29

    [Pettit] Exactly. And as it says on the site,

  • 1:33

    your site is being viewed by increasingly smaller, slower,

  • 1:37

    and low bandwidth devices.

  • 1:40

    [Seifer] That's good news. >>Yeah. That's great.

  • 1:43

    [Seifer] Awesome. >>All right.

  • 1:45

    [Seifer] So along those lines, and completely not along those lines,

  • 1:48

    next up is Snappy Dashboards with Redis.

  • 1:52

    Now, Nick, you've probably seen applications where you log into the app

  • 1:56

    and it has a dashboard overview of what's going on,

  • 1:58

    maybe how many clicks were someplace, or a bar graph of what's going on. >>Exactly.

  • 2:04

    [Seifer] Well, it can occasionally be very cumbersome

  • 2:07

    to get at that data if you're using a relational database.

  • 2:10

    This could take a lot of different queries to see the proper information,

  • 2:15

    and it can wind up becoming a little bit expensive.

  • 2:18

    [Pettit] Because you have to pull together all these various pieces of information.

  • 2:22

    [Seifer] Yeah. You have to assemble a whole bunch.

  • 2:23

    So there's an interesting blog post called "Snappy Dashboards with Redis."

  • 2:29

    Now, this talks about using Redis, which is one of these

  • 2:32

    newfangled, NoSQL databases. >>Whoa. >>I know.

  • 2:37

    A lot of words there. A lot of words.

  • 2:40

    But what Redis does is, essentially, it's like a glorified key value store that's persistent.

  • 2:45

    So the technique that they use in this post is concatenating

  • 2:50

    all your different statistics with certain Redis keys

  • 2:53

    that are going to be a lot quicker to increment and decrement.

  • 2:57

    This way, when you want to create a dashboard,

  • 2:59

    you only have to do a limited amount of querying

  • 3:02

    from Redis rather than your database.

  • 3:05

    This is going to result in a lot quicker page use for your users.

  • 3:09

    The blog post has more specific techniques on how they wound up doing this,

  • 3:13

    and the different keys that they wound up using,

  • 3:17

    and even some sample Ruby code in order to do this.

  • 3:20

    This is definitely something that you're going to want to

  • 3:23

    read the show notes for for more information,

  • 3:25

    and you can find the show notes on our YouTube channel

  • 3:28

    at youtube.com/gotreehouse.

  • 3:31

    [Pettit] All right. Go treehouse. So next up,

  • 3:34

    we're going to talk about how to create a responsive SVG.

  • 3:39

    [Seifer] Now, is it true that people are pronounicing SVG as "savage?"

  • 3:42

    [Pettit] No. I think that's actually just you, Jason.

  • 3:45

    [Seifer] Thought I read that somewhere. >>Nope.

  • 3:47

    You just made that up. All right.

  • 3:51

    Actually, we're not going to tell you how to do it, we're going to direct you

  • 3:53

    to this really great blog post that tells you exactly how to do it.

  • 3:57

    And actually, it's very simple.

  • 4:00

    It's very simple to creating a fluid image.

  • 4:03

    Basically, you would create your vector image in Illustrator,

  • 4:09

    and you want to go ahead and export it as an SVG.

  • 4:12

    I am kind of glossing over this a little bit,

  • 4:16

    but ultimately, you'll end up with some HTML that is your SVG,

  • 4:21

    and you can put that into your HTML document, I should say.

  • 4:26

    Then, in your CSS, you can go ahead and set the width to 100%.

  • 4:33

    That's very similar to what you would do for images in a responsive website.

  • 4:38

    What this is going to do is it's going to cause the SVG

  • 4:41

    to take up the full width of its parent element,

  • 4:44

    and that way, if you're resizing the browser in a fluid layout,

  • 4:51

    it will go ahead and just continue to expand or contract proportionally.

  • 4:58

    Pretty nifty, and again, it's very similar to fluid images,

  • 5:02

    but it's something that, I don't know, I wouldn't have known that had I not read it.

  • 5:08

    [Seifer] I'm pretty sure it's pronounced "savages."

  • 5:11

    [Pettit] I think you're right, Jason. I'll let you go on thinking that.

  • 5:14

    [Seifer] Thanks. Next up is our app review.

  • 5:18

    [Pettit] Let's check it out.

  • 5:22

    [App Review]

  • 5:26

    [Seifer] Our app review this week is an app called Shortcat.

  • 5:29

    [Pettit] And that has nothing to do with Longcat. >>Except it's the opposite. >>Got it.

  • 5:34

    [Seifer] Shortcat is a very interesting application for OS X.

  • 5:38

    And this is going to give you the ability to interface with GUI elements using the keyboard.

  • 5:46

    Now, I know that's a little bit strange to say,

  • 5:48

    but you get a command prompt, and--yeah, here we go.

  • 5:52

    Cut to it. You'll notice this little video they have on the site in system preferences.

  • 5:57

    [Pettit] I only notice the really cute cat.

  • 5:59

    [Seifer]. Yeah, look at that. Look at that cat.

  • 6:01

    It's got a little computer mouse hanging from its mouth.

  • 6:04

    [Pettit] That's crazy. >>I know.

  • 6:08

    So the example that they give is in system preferences,

  • 6:10

    and if you wanted to go to the network preference,

  • 6:13

    you do the Shortcat shortcut, and press the letter 'n' for network.

  • 6:20

    Then you can completely navigate around the OS X GUI using Shortcat.

  • 6:26

    What I found that's really interesting is it works with Chrome as well.

  • 6:31

    So let me see if I can get my navigation bar up here

  • 6:33

    So I launch Shortcat with command + shift + space.

  • 6:37

    You see the little cat eyes come up on the bottom of the screen,

  • 6:40

    and if I wanted to access the Chrome menu, I could type 'c,'

  • 6:44

    and you can see in the top right corner of the screen it gets highlighted in green,

  • 6:48

    press enter, and it shows you what's going on.

  • 6:51

    [Pettit] Huh. That's pretty cool. >>Really, really good app.

  • 6:54

    Saves a lot of time.

  • 6:57

    Well, you know. Gives you a lot of shortcuts with Shortcat.

  • 7:00

    [Pettit] And, you know, shortcuts are actually one of those interesting things

  • 7:03

    that, they never seem like they're going to save a lot of time,

  • 7:06

    but actually moving your mouse around the screen, as lazy as this sounds,

  • 7:12

    it does take a lot of time to click on small, little buttons.

  • 7:16

    So anything that you can do with the keyboard is probably going to speed up your workflow.

  • 7:21

    In fact, Jason introduced me to Gmail shortcuts in 2012.

  • 7:27

    [Seifer] I don't know how you lived. >>I didn't, Jason. Not until now.

  • 7:30

    [Seifer] You weren't really living. >>Exactly.

  • 7:33

    So next up is Enquire.js, which is available at this really long URL

  • 7:40

    which will be in the lower third.

  • 7:42

    Basically, Enquire.js is a way for you to include media queries in JavaScript.

  • 7:51

    [Seifer] So that's what it does. Inquiring minds wanted to know. >>Huh. >>Huh. >>Okay, enough.

  • 8:00

    This sounds a little bit crazy, and that might be what you're inquiring about, Jason.

  • 8:06

    Including media queries in your JavaScript sounds a little strange, right?

  • 8:10

    You normally include media queries in your CSS.

  • 8:14

    When you're creating a responsive design,

  • 8:17

    you want to go ahead and create your fluid grid,

  • 8:20

    and then as that starts to break down towards

  • 8:23

    smaller and smaller or larger and larger screen sizes,

  • 8:26

    you use media queries to apply different CSS to change the layout.

  • 8:32

    Now, in JavaScript, you can actually do something very similar,

  • 8:37

    but instead of applying different styling,

  • 8:40

    Enquire.js allows you to apply different JavaScript.

  • 8:45

    So as you start to get towards a larger screen size or a smaller screen size,

  • 8:50

    there might be different functions that you want to use

  • 8:54

    or different pieces of JavaScript entirely.

  • 8:58

    And you don't necessarily need it in other types of layouts.

  • 9:02

    So that's pretty handy, because it's probably going to end up

  • 9:04

    saving you CPU cycles when you're not executing different pieces of code.

  • 9:10

    So it's pretty nifty. >>I think it'll also clean up your code quite a bit,

  • 9:13

    whereas rather than hooking in to the window resize event

  • 9:16

    and checking the width and duplicating all of that,

  • 9:19

    just put in the media query. >>Yeah, exactly.

  • 9:22

    And the nice thing about it is it's super, super tiny.

  • 9:25

    I think it's only like a kilobyte or less, something like that.

  • 9:30

    And it doesn't have any dependencies, so you don't need jQuery.

  • 9:34

    You can just go ahead and use Enquire.js in your next web project

  • 9:38

    and enjoy blissful JavaScript goodness.

  • 9:43

    [Seifer] That, I think, is the show title.

  • 9:45

    "Blissful JavaScript Goodness." >>Got it.

  • 9:48

    [Seifer] Next up, there is a great blog post over on the NetTuts blog

  • 9:52

    on how to customize your command prompt.

  • 9:55

    As you may have been able to tell with the Shortcat review,

  • 9: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]

Show full transcript


You have to sign up for Treehouse in order to create workspaces.

Sign up


You have to sign up for Treehouse in order to download course videos.

Sign up


  • Nick Pettit

    Nick is a designer, public speaker, teacher at Treehouse, and co-host of The Treehouse Show. His Twitter handle is @nickrp.

  • Jason Seifer

    When not fighting web crime, Jason Seifer is a teacher at Treehouse. He's passionate about the web and programming. You can find Jason on Twitter at @jseifer and on his personal blog at jasonseifer.com.