Santa Tracker Developer Diary #3: Build & Scenes

Chrome for Developers · Beginner ·📰 AI News & Updates ·8y ago

Key Takeaways

Builds and explains the scenes of the Santa Tracker site as a Progressive Web App

Full Transcript

hey everyone it's Sam here so you might have watched a few episodes so far and learned a little bit about the different paths of Santa Tracker and how it works but what I wanted to do today is talk about how you actually build it yourself and how you can you know quite literally check out the source code and run your own version so to start with let's have a look at our command line we've already checked out Santa tracker you know we've gone to get hopping caught the repo and let's look at what we do now start by checking it out you can have a look we've got some content here it's got a bunch of stuff so what you can start with this is by basically running yarn install and so yarns a package manager you can fetch that with homebrew or some equivalent on your machine and it will then go and do a bunch of stuff in our case you can see here it's pretty fast because I've actually checked it out before and so it'll go and fetch all its dependencies and things like that what it's actually doing is it's internally calling Bower which is a package management talks a little bit older it's still needed for polymer - I know polymer 3 is upgrading to NPM and that repository but for now we still need to have Bower install to check out all the code we then run our build tool which is using the gulp build system so that a fault task that we have in gulp will build 10 a tracker it will actually let us serve that folder so if I just run serve here and hit enter and then load it up and load this URL we'll see that take a few seconds to load and Santa tracker will load up with all its fun exciting stuff going on this version will be a little bit slower than the production version for a bunch of reasons which I'll kind of cover in a few seconds so because we're developers and you know we've got access to Santa's Village whenever we like you can actually go and click on these scenes to see what's going on so we can you know cut Santa's beard and things like that one thing to think about is that these scenes will lo dynamically so if we load the dev tools thusly we'll see our lovely responsive design and if we go to network here and set the speed to say fast 3G we can see the loading happen so we actually loaded the Santa selfie scene so that'll load really fast well let's go to a scene we haven't loaded yet so this might be the gift slingshot and I love this scene which I call boatload that's that's an actual ID because it's actually pretty small it's not too complicated yet it does most of the things that a regular Santa scene will do and we've got you know every house in the village these is what we call a scene so let's click on that now what you can notice is that we're actually it was a red bar at the top here and that slowly moves across the screen has all the resources that are on the right here are loaded into the page and this is a pretty small scene so it loads pretty fast even on a slow connection we can also play this game so how do we get to these scenes if we go to the code and look at Santa app dot HTML this is a polymer element and we've had another episode in polymer so I won't cover this extensively in the middle here is what we call the lazy pages element and this element is entirely designed to load these pages at runtime so interestingly enough these scenes aren't on the page when you load Santa tracker these are essentially unknown HTML elements that your browser doesn't know how to render what lazy pages does is that when the route changes to that URL when we want to load the boat load scene for instance it then goes and finds okay here's the boat load scene it goes cool the path is this HTML path including a language field it then loads that into the page and when that's loaded we can then show that scene because all the resources to do with that element are now on the page so if you notice we've got it open as well so a couple of things to note here so firstly is that we bring in the JavaScript for the scene so when you first build and check out that rack up your build might still be running because we actually compile every scenes JavaScript with closure compiler the reason we do this is actually because a lot of the scenes are quite old they typically predate the majority of scenes predate polymer and there's a few scenes which are very modern and there are built a little bit differently most of our games are written fairly generically they don't really care about polymer and actually there's kind of a nice strength of polymer in that we kind of wrap up the HTML and JavaScript in a very neat way just within this one file so this scene is made of a bunch of things it's got a template which includes the kind of inbuilt style we care about it also has a bunch of divs and elements like trees and elves and stuff like this is the the cute things you see around this the the slingshot thing a bit down a bit further below we've got a very interesting message here this is a i18n message in production we actually remove this div completely we swap it out for or the message that's appropriate for your language but in dev it lives here so we can quickly slash line switch languages you actually see it as we go to the site and we go to console and type document.documentelement dot lang equals let's say German and a few seconds later we see all the language stuff changes and the way we do that is within that element but in production we've actually got rid of that element completely if you're curious about how we do that you actually load up the gulp scripts the replace script here and so we have a look around what we do is actually load each page into memory which is this mutate function here and we do regular query selectors we say so for everything with a message ID or everything with a of this tag name okay this actually is the wrong oh I see because each method has that message ID so we catch it here first well actually replace the content of that message ID for that language so that's kind of cool that's part of our build processes as well and so finally let's talk a little bit about gulp so I mentioned earlier that we use gulp to build stuff we can also use gulp to serve things so if we type gulp serve here or actually see it'll do the same thing we'll do this default compile step which yet again is happening pretty fast for me and they'll actually run a web server so this is the kind of the best way to run it and test and track yourself and this serve command as well we'll also do auto reloading so if I change something let's say I change this boat load scene to have some text just somewhere hello then what you'll see is this page will automatically reload and actually what you want even on that scene but if we load it up you can sort of see that text now appearing there oh there we go very subtly in the corner there's a hello so hopefully you've learned a little bit about the way you can build and test Santa tracker even on your own machine so Santa tracker is a big complicated single page application it really has one entry point and then it loads these individual scenes as we need them which is super interesting in itself if you want to learn a little bit more about that and also build instructions of how to run and built a no trucker there's some links below the article I'm linking to is an article I wrote last year which talks about how Santa tracker was made into a progressive web app and while of course that's a little bit of a different topic it actually covers a little bit of about and this is important because as a PWA we care about offline and caching and so one thing we do that's interesting is that we only catch scenes users have been to before and that matches the way we load scenes only these users need them rather than loading the whole site at once so thanks for watching and I'll see you next time thanks for watching you can subscribe to the google chrome developer channel down here we'll check out some other great videos along here

Original Description

Learn more about Santa Tracker's build process, and the scenes that make the site tick—with Sam in this episode of the Santa Tracker 🎅🎄🎁 Developer Diary. Read the article 'Santa as a PWA' here: https://goo.gl/DtGtMB https://github.com/google/santa-tracker-web https://santatracker.google.com Watch the rest of the series here: https://goo.gl/UD214n Subscribe to the Chrome Developers channel: http://goo.gl/LLLNvf
Watch on YouTube ↗ (saves to browser)
Sign in to unlock AI tutor explanation · ⚡30

Playlist

Uploads from Chrome for Developers · Chrome for Developers · 0 of 60

← Previous Next →
1 Polymer Performance Patterns (The Polymer Summit 2015)
Polymer Performance Patterns (The Polymer Summit 2015)
Chrome for Developers
2 Polymer Power Tools (The Polymer Summit 2015)
Polymer Power Tools (The Polymer Summit 2015)
Chrome for Developers
3 Chrome Dev Summit 2014 – Chrome Case Studies
Chrome Dev Summit 2014 – Chrome Case Studies
Chrome for Developers
4 Web Directions Code 2015 round up
Web Directions Code 2015 round up
Chrome for Developers
5 Maintainable Code - HTTP203
Maintainable Code - HTTP203
Chrome for Developers
6 iron-ajax… wat?! -- Polycasts #26
iron-ajax… wat?! -- Polycasts #26
Chrome for Developers
7 The Guardian - Supercharged
The Guardian - Supercharged
Chrome for Developers
8 ES2015 (next version of JavaScript), Totally Tooling Tips (S2 Ep1)
ES2015 (next version of JavaScript), Totally Tooling Tips (S2 Ep1)
Chrome for Developers
9 #AskPolymer: Rob answers all the questions ever -- Polycasts #27
#AskPolymer: Rob answers all the questions ever -- Polycasts #27
Chrome for Developers
10 The Future of JavaScript - HTTP203
The Future of JavaScript - HTTP203
Chrome for Developers
11 Data Binding 101 -- Polycasts #28
Data Binding 101 -- Polycasts #28
Chrome for Developers
12 The Guardian part 2 - Supercharged
The Guardian part 2 - Supercharged
Chrome for Developers
13 The Future of Web Audio: with Chris Wilson and Chris Lowis
The Future of Web Audio: with Chris Wilson and Chris Lowis
Chrome for Developers
14 Chrome 46: New motion-path animations, client hints and service worker improvements
Chrome 46: New motion-path animations, client hints and service worker improvements
Chrome for Developers
15 Sublime Snippets, Totally Tooling Tips (S2 Ep2)
Sublime Snippets, Totally Tooling Tips (S2 Ep2)
Chrome for Developers
16 #AskPolymer: How do you make the show? -- Polycasts #29
#AskPolymer: How do you make the show? -- Polycasts #29
Chrome for Developers
17 Critical Path CSS, Totally Tooling Tips (S2 Mini Tip #1)
Critical Path CSS, Totally Tooling Tips (S2 Mini Tip #1)
Chrome for Developers
18 Binding to Objects -- Polycasts #30
Binding to Objects -- Polycasts #30
Chrome for Developers
19 Player FM - Supercharged
Player FM - Supercharged
Chrome for Developers
20 Where’s the Designer? #AskPolymer -- Polycasts #31
Where’s the Designer? #AskPolymer -- Polycasts #31
Chrome for Developers
21 Jake Beats Wikipedia - HTTP203
Jake Beats Wikipedia - HTTP203
Chrome for Developers
22 Supercharged Observers! -- Polycasts #32
Supercharged Observers! -- Polycasts #32
Chrome for Developers
23 Jai's Web blog - Supercharged
Jai's Web blog - Supercharged
Chrome for Developers
24 Windows Command-line Tooling, Totally Tooling Tips (S2, Ep4)
Windows Command-line Tooling, Totally Tooling Tips (S2, Ep4)
Chrome for Developers
25 What about internationalization? #AskPolymer -- Polycasts #33
What about internationalization? #AskPolymer -- Polycasts #33
Chrome for Developers
26 Developing for Billions (Chrome Dev Summit 2015)
Developing for Billions (Chrome Dev Summit 2015)
Chrome for Developers
27 Google+ Performance Improvement Comparison
Google+ Performance Improvement Comparison
Chrome for Developers
28 Deploying HTTPS: The Green Lock and Beyond (Chrome Dev Summit 2015)
Deploying HTTPS: The Green Lock and Beyond (Chrome Dev Summit 2015)
Chrome for Developers
29 Progressive Web Apps (Chrome Dev Summit 2015)
Progressive Web Apps (Chrome Dev Summit 2015)
Chrome for Developers
30 Instant Loading with Service Workers (Chrome Dev Summit 2015)
Instant Loading with Service Workers (Chrome Dev Summit 2015)
Chrome for Developers
31 Increase Engagement with Web Push Notifications (Chrome Dev Summit 2015)
Increase Engagement with Web Push Notifications (Chrome Dev Summit 2015)
Chrome for Developers
32 Engaging with the Real World: Web Bluetooth and Physical Web (Chrome Dev Summit 2015)
Engaging with the Real World: Web Bluetooth and Physical Web (Chrome Dev Summit 2015)
Chrome for Developers
33 Asking for Permission: respectful, opinionated UI (Chrome Dev Summit 2015)
Asking for Permission: respectful, opinionated UI (Chrome Dev Summit 2015)
Chrome for Developers
34 Polymer - State of the Union (Chrome Dev Summit 2015)
Polymer - State of the Union (Chrome Dev Summit 2015)
Chrome for Developers
35 Building Progressive Web Apps with Polymer (Chrome Dev Summit 2015)
Building Progressive Web Apps with Polymer (Chrome Dev Summit 2015)
Chrome for Developers
36 Introduction to RAIL (Chrome Dev Summit 2015)
Introduction to RAIL (Chrome Dev Summit 2015)
Chrome for Developers
37 DevTools in 2015: Authoring to the max (Chrome Dev Summit 2015)
DevTools in 2015: Authoring to the max (Chrome Dev Summit 2015)
Chrome for Developers
38 RAIL in the real world (Chrome Dev Summit 2015)
RAIL in the real world (Chrome Dev Summit 2015)
Chrome for Developers
39 #ChromeDevSummit talks are up - W00T! -- Polycast #34
#ChromeDevSummit talks are up - W00T! -- Polycast #34
Chrome for Developers
40 V8 Performance from the Driver's Seat (Chrome Dev Summit 2015)
V8 Performance from the Driver's Seat (Chrome Dev Summit 2015)
Chrome for Developers
41 Quantify and improve real-world RAIL (Chrome Dev Summit 2015)
Quantify and improve real-world RAIL (Chrome Dev Summit 2015)
Chrome for Developers
42 Owning your performance: RAIL (Chrome Dev Summit 2015)
Owning your performance: RAIL (Chrome Dev Summit 2015)
Chrome for Developers
43 HTTP/2 101 (Chrome Dev Summit 2015)
HTTP/2 101 (Chrome Dev Summit 2015)
Chrome for Developers
44 Leadership Panel (Chrome Dev Summit 2015)
Leadership Panel (Chrome Dev Summit 2015)
Chrome for Developers
45 Build Processes, Totally Tooling Tips (S2, Ep 5)
Build Processes, Totally Tooling Tips (S2, Ep 5)
Chrome for Developers
46 Accessibility (Chrome Dev Summit 2015)
Accessibility (Chrome Dev Summit 2015)
Chrome for Developers
47 Binding to Arrays -- Polycasts #35
Binding to Arrays -- Polycasts #35
Chrome for Developers
48 HTTP2 - HTTP203
HTTP2 - HTTP203
Chrome for Developers
49 Chrome 47: Splash Screens, requestIdleCallback and better desktop notifications (New in Chrome)
Chrome 47: Splash Screens, requestIdleCallback and better desktop notifications (New in Chrome)
Chrome for Developers
50 Call For Submissions - Supercharged
Call For Submissions - Supercharged
Chrome for Developers
51 Cross Device Testing, Totally Tooling Tips (S2 Ep6)
Cross Device Testing, Totally Tooling Tips (S2 Ep6)
Chrome for Developers
52 Testing AJAX with Web Component Tester -- Polycasts #37
Testing AJAX with Web Component Tester -- Polycasts #37
Chrome for Developers
53 Slack: Extended Xmas Special - Supercharged
Slack: Extended Xmas Special - Supercharged
Chrome for Developers
54 Browser testing with Travis & Sauce Labs -- Polycasts #38
Browser testing with Travis & Sauce Labs -- Polycasts #38
Chrome for Developers
55 Optimize for production with Vulcanize -- Polycasts #39
Optimize for production with Vulcanize -- Polycasts #39
Chrome for Developers
56 Highlights from Chrome Dev Summit 2015
Highlights from Chrome Dev Summit 2015
Chrome for Developers
57 Chrome 48: Custom buttons in notifications, DevTools Security panel, and Presentation mode
Chrome 48: Custom buttons in notifications, DevTools Security panel, and Presentation mode
Chrome for Developers
58 Crisper: Protecting your Polymer app with CSP -- Polycasts #40
Crisper: Protecting your Polymer app with CSP -- Polycasts #40
Chrome for Developers
59 How do I use Sass with Polymer? #AskPolymer -- Polycasts #41
How do I use Sass with Polymer? #AskPolymer -- Polycasts #41
Chrome for Developers
60 Colors – DevTools Tonight #0 (Pilot)
Colors – DevTools Tonight #0 (Pilot)
Chrome for Developers

Related Reads

📰
Google Is Winning the AI Race and Losing Its Business Model at the Same Time
Google is leading in AI development but its business model is under threat due to changes in search behavior and advertising revenue, learn how AI is disrupting traditional business models
Medium · AI
📰
AI Will Not Save You from Thinking: Why Polymathy Is Becoming the Real Career Advantage
Learn why polymathy is crucial in an AI-driven career and how to develop it to stay ahead
Medium · AI
📰
The Apple Intelligence Compromise: Why China is Forcing Apple to Use Local AI Models
Apple must use local AI models in China, highlighting geopolitical tensions in tech
Medium · AI
📰
Everything You Know About AI Needs an Urgent Upgrade
Upgrade your understanding of AI to keep pace with rapid advancements in the field
Medium · Programming
Up next
Mythos Hype is Absurd! You Already Have AI Tools #shorts
Income stream surfers
Watch →