Introducing RequireJS into Large Codebases. Delicately.

29
Introducing RequireJS Into a Large Codebase. Delicately. Dan Lee & Chris Chen

description

We're going to talk about how Yammer's JavaScript codebase grew to over 100k lines without any notion of Dependency Management, and how we were recently able to introduce Dependency Management into that codebase in a safe and iterative way.

Transcript of Introducing RequireJS into Large Codebases. Delicately.

Page 1: Introducing RequireJS into Large Codebases. Delicately.

Introducing RequireJS Into a Large Codebase. Delicately.Dan Lee & Chris Chen

Page 2: Introducing RequireJS into Large Codebases. Delicately.

2008 TechCrunch 50

Source: http://techcrunch.com/2008/09/10/yammer-takes-techcrunch50s-top-prize/

Page 3: Introducing RequireJS into Large Codebases. Delicately.

get_it_done.js- nested erb partials- deferred JS- variable interpolation- global jQuery

Page 4: Introducing RequireJS into Large Codebases. Delicately.

@polotek @techwraith @mde

@foobarfighter @peterbraden @mattkauffman

They made us better.

Page 5: Introducing RequireJS into Large Codebases. Delicately.

Modular components

Page 6: Introducing RequireJS into Large Codebases. Delicately.

build.jsonor manifest.ymlor scripts.json…

Page 7: Introducing RequireJS into Large Codebases. Delicately.

Build and Deployment

build.json Asset Pipeline

application.js CDN

Page 8: Introducing RequireJS into Large Codebases. Delicately.

Bob wants more.

Page 9: Introducing RequireJS into Large Codebases. Delicately.

Popout Chat

Page 10: Introducing RequireJS into Large Codebases. Delicately.

“Programming out of Anger”

Page 11: Introducing RequireJS into Large Codebases. Delicately.

The Chat Bundle ChatBundle

ChatManager

ContactList ChatSession

ChatSessionNotifications ChatMessageList

ChatMessageListItem

Avatar

ChatPublisher

ChatAggregator ChatBridge

Page 12: Introducing RequireJS into Large Codebases. Delicately.

AMD’ing ChatManager

Page 13: Introducing RequireJS into Large Codebases. Delicately.

But chat also loads on yammer.com…

Page 14: Introducing RequireJS into Large Codebases. Delicately.

define() doesn’t exist

Page 15: Introducing RequireJS into Large Codebases. Delicately.

We needed a version of define() that ignored dependencies.

So we shimmed it.

Page 16: Introducing RequireJS into Large Codebases. Delicately.

Wait, don’t get up…Think about the possibilities.

Page 17: Introducing RequireJS into Large Codebases. Delicately.

Feature flags that aren’t used for features…

Page 18: Introducing RequireJS into Large Codebases. Delicately.

The resultsBefore:Compressed: 531kbUncompressed: 2048kb

After:Compressed: 216kbUncompressed: 715kbA 60% reduction!

build.json Asset Pipeline

Way too much JS CDN

ChatBundle r.js optimizer popout_chat.js CDN

Page 19: Introducing RequireJS into Large Codebases. Delicately.

The dream is real.Yammer is saved!

Page 20: Introducing RequireJS into Large Codebases. Delicately.

But, we didn’t really save Yammer.- AMD’ed a small percentage of files- Dev environment setup- Two worlds- Global namespaces

Page 21: Introducing RequireJS into Large Codebases. Delicately.

How we moved forward.And there is still more to do.

Page 22: Introducing RequireJS into Large Codebases. Delicately.

Reflection

Page 23: Introducing RequireJS into Large Codebases. Delicately.

- Big- Deployed often- Many, globally distributed contributors

Codebase challenges

Page 24: Introducing RequireJS into Large Codebases. Delicately.

1. Isolation

Page 25: Introducing RequireJS into Large Codebases. Delicately.

2. Iteration

Page 26: Introducing RequireJS into Large Codebases. Delicately.

3. Minimize Disruption

Page 27: Introducing RequireJS into Large Codebases. Delicately.

‘Code in Transition’ is OK

Page 28: Introducing RequireJS into Large Codebases. Delicately.

Transition or Stagnation:Choose One.

Page 29: Introducing RequireJS into Large Codebases. Delicately.

© 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries.The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.