Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lazy load menu, chops 30k from the main bundle. #37

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions src/app/containers/application/Application.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,19 @@ import React, { Component, PropTypes } from 'react';
import { connect } from 'react-redux';
import ReactCSSTransitionGroup from 'react-addons-css-transition-group';
import LoadingBar from '../../components/loading-bar/LoadingBar';
import Menu from '../menu/Menu';
import { canSmoothScroll } from './util/smoothScroll';

let Menu; // Menu component will be lazy loaded here

class Application extends Component {
componentDidMount() {
// Lazy load the Menu because it's too heavy due to snapsvg
require.ensure([], (require) => {
Menu = require('../menu/Menu').default;
this.forceUpdate();
}, 'menu');
}

render() {
return (
<div id="application">
Expand All @@ -15,7 +24,7 @@ class Application extends Component {
</div>

<div id="menu">
<Menu />
{ Menu ? <Menu /> : '' }
</div>

<div id="page">
Expand Down
41 changes: 29 additions & 12 deletions src/shared/containers/header/Header.css
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
vertical-align: middle;
}

/* Logo
========================================================================== */

.header-component .logo {
width: 20px;
padding-left: 20px;
Expand Down Expand Up @@ -42,40 +45,54 @@
text-decoration: none;
}

/* Search box tweeks
========================================================================== */

.header-component .search-box .search-box-component {
max-width: 700px;
}

/* Right side actions
========================================================================== */

.header-component .other-actions {
width: 160px;
text-align: right;
user-select: none;
}

.header-component .other-actions .social-link {
width: 24px;
height: 24px;
margin-right: 15px;
display: inline-block;
fill: #fff;
}

.header-component .other-actions .social-link:hover {
fill: #1dd09b;
}

.header-component .other-actions .toggle-menu {
margin-right: 17px; /* Should be 20px but icon is centered */
display: inline-block;
vertical-align: middle;
}

.header-component .other-actions .toggle-menu i {
cursor: pointer;
opacity: 0.3;
pointer-events: none;
transition: opacity 0.2s linear;
}

.header-component .other-actions .toggle-menu:hover {
color: #1dd09b;
}

.header-component .other-actions .social-link {
width: 24px;
height: 24px;
margin-right: 15px;
display: inline-block;
fill: #fff;
.is-menu-mounted .header-component .other-actions .toggle-menu {
opacity: 1;
pointer-events: auto;
}

.header-component .other-actions .social-link:hover {
fill: #1dd09b;
.header-component .other-actions .toggle-menu i {
cursor: pointer;
}

/* Utility classes to be used by several pages
Expand Down