FRONT-END PRODUCTION
MICHAEL HABERMAN
Your code is Awesome

Your code has deployed

What happen when users consume it?
Users cause problems
A lot of browsers and operation systems

They cause bugs

They don’t follow the QA’a scenarios

Code changes from dev to prod 

They install extensions in browsers

They have anti-viruses
Today’s Task
Go over stories we have encountered

Reproduce them

Fix them

Understand how to be prepared for next time
User story
A long long time ago…

New developer wrote some code…
User story - solution
Capture all errors

Send your error to somewhere (sentry, rollbar, etc…)
User story - continue
Start tracking and analyse your errors

“griddy.js” - Anyone?
JS in production?
Minify

Uglify

Concat

Why?

Same goes for CSS
Gulp & Grunt
Two Great tools

Gulp - more code like

Grunt - more config like

Just take your pick
Gulp
gulp.src(‘*.js’).pipe(concat()).pipe(gulp.dest(‘/jsFiles.js’);
Grant
grunt.initConfig({

concat:{

‘allFiles.js’ : ’*.js’

}

});

grunt.run(‘concat’);
Gulp
Personally I like gulp better

Lets minify and concat our code
User story
Sentry will provide your call-stack.

What will happen to the call stack once minified?
User story - partial solution
Source Maps
User story - partial solution
Context log
Website Deployment
First thing, where do you get your libraries from?

NPM

Bower
NPM
Node Package Manager

Each package is isolated

No conflicts

Larger JS files
NPM
Bower
A NPM library

Each package is not isolated

Conflicts may occur

Smaller JS files
Website Deployment
Deployment script:

git pull

npm install - (fresh environment)

gulp deploy
Website Deployment
How will the new version won’t be cached?
Website Deployment
<script src=‘build/app.js?v=123’></script>

using gulp & package.json
We need to set the version
number somewhere
Website Deployment
How to handle environment configuration?
Website Deployment
Minify & concat

Set version

Copy to new location
Deployment & source control
FB #1
FB #3 FB #4
FB #2
DEV
Integration
QA
Staging
Production
Integration Server
QA Server
Staging Server
Production Server
Browser caching
Browser caching
Browser caching
Cache-control options:

max-age: time in seconds

private / public

no-cache / no-store
Browser caching
Cross Origin Resource Sharing
Security risk

You may get data

You may not send data (body)
Cross Origin Resource Sharing
Cross Origin Resource Sharing
Request headers

Origin

Access-Control-Request-Method

Access-Control-Request-Headers
Cross Origin Resource Sharing
Response headers

Access-Control-Allow-Origin

Access-Control-Allow-Credentials

Access-Control-Expose-Headers

Access-Control-Max-Age

Access-Control-Allow-Methods

Access-Control-Allow-Headers
Browser Storage
Cookie

Local Storage

Local Session
Browser Storage - Cookie
Why it called cookie?
Browser Storage - Cookie
Expire by date

Control HTTP / HTTPS

Cookie type

first party

third party

super cookie

Max size ~4MB
Browser Storage - Cookie
Can be set by client side

Can be set by HTTP Response:

HTTP/1.0 200 OK

Content-type: text/html

Set-Cookie: theme=light

Set-Cookie: sessionToken=abc123; Expires=Wed, 09 Jun 2021
10:18:14 GMT
Browser Storage - Cookie
HTTP/1.0 200 OK

Set-Cookie: A=1; Path=/accounts; Expires=Wed, 13 Jan 2021 22:23:01
GMT; Secure; 

Set-Cookie: B=2; Domain=.foo.com; Path=/; Expires=Wed, 13 Jan
2021 22:23:01 GMT; HttpOnly

Set-Cookie: C=3; Domain=foo.com; Path=/; Expires=Wed, 13 Jan 2021
22:23:01 GMT; Secure; HttpOnly

*** Being sent to server with every matching request
Browser Storage - Cookie
Browser may block the cookies…

Create fallback
Not being sent to server, no expiration, no path…

~ 10MB

Persistence across instances
Browser Storage - Local Storage
Browser Storage - Session Storage
Not being sent to server, no expiration, no path…

~ 10MB

Closes with the tab instance
User story
HTTPS using SSL Certificate

SSL use encryption algorithm

SHA1 is being deprecated

Moving to SHA2 ?
User story
Using Angular 1.2

You want to migrate to 1.3?
Google Analytics
Developer should use that tool!

You must know your audience:

Browser

OS

Device

Resolution

Language / country

User flow - reproduce bugs
Google Analytics
Set user ID

Send event is also for developers

SPA - HTML5 Anchor

Send url manually 

Aggregate - /item/{{id}}
Before Production
Error testing

Memory Profiling (for SPA apps)

Cross platform tests 

Rollback testing
During Dev
Try to have the same configuration

Two server instances
Questions?
Thank you!
michael@haberman.io

@hab_mic

Javascript issues and tools in production for developers