mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-29 23:58:06 +01:00
0f8a9a5d49
The CSS is now served as an external file instead of being injected. This was done to improve performance. Ideally we would come to a middle ground between this and the former behaviour by injecting only the CSS that was required for the initial page load, then lazily loading the rest. However that change would be more complex. The hope was that making all CSS external would at least be a slight improvement. Performance metrics were collected before and after this change to determine whether this change actually helped. The metrics collected were the timing events provided by Chrome DevTools: * DOM Content Loaded (DCL) [1] * Load (L) [2] * First Paint (FP) [3] * First Contentful Paint (FCP) [3] * First Meaningful Paint (FMP) [3] Here are the results (units in milliseconds): Injected CSS: | Run | DCL | L | FP | FCP | FMP | | :--- | ---: | ---: | ---: | ---: | ---: | | 1 | 1569.45 | 1570.97 | 1700.36 | 1700.36 | 1700.36 | | 2 | 1517.37 | 1518.84 | 1630.98 | 1630.98 | 1630.98 | | 3 | 1603.71 | 1605.31 | 1712.56 | 1712.56 | 1712.56 | | 4 | 1522.15 | 1523.72 | 1629.3 | 1629.3 | 1629.3 | | **Min** | 1517.37 | 1518.84 | 1629.3 | 1629.3 | 1629.3 | | **Max** | 1603.71 | 1605.31 | 1712.56 | 1712.56 | 1712.56 | | **Mean** | 1553.17 | 1554.71 | 1668.3 | 1668.3 | 1668.3 | | **Std. dev.** | 33.41 | 33.43 | 38.16 | 38.16 | 38.16 | External CSS: | Run | DCL | L | FP | FCP | FMP | | :--- | ---: | ---: | ---: | ---: | ---: | | 1 | 1595.4 | 1598.91 | 284.97 | 1712.86 | 1712.86 | | 2 | 1537.55 | 1538.99 | 199.38 | 1633.5 | 1633.5 | | 3 | 1571.28 | 1572.74 | 268.65 | 1677.03 | 1677.03 | | 4 | 1510.98 | 1512.33 | 206.72 | 1607.03 | 1607.03 | | **Min** | 1510.98 | 1512.33 | 199.38 | 1607.03 | 1607.03 | | **Max** | 1595.4 | 1598.91 | 284.97 | 1712.86 | 1712.86 | | **Mean** | 1553.8025 | 1555.7425 | 239.93 | 1657.605 | 1657.605 | | **Std. dev.** | 29.5375 | 30.0825 | 36.88 | 37.34 | 37.34 | Unfortunately, using an external CSS file made no discernible improvement to the overall page load time. DCM and L were practically identical, and FCP and FMP were marginally better (well within error margins). However, the first paint time was _dramatically_ improved. This change seems worthwhile for the first paint time improvement alone. It also allows us to delete some code and remove a dependency. The old `css.js` module included two third-party CSS files as well, so those have been imported into the main Sass file. This was easier than bundling them in the gulpfile. The resulting CSS bundle needs to be served from the root because we're using a few `@include` rules that make this assumption. We could move this under `/css/` if desired, but we'd need to update each of these `@include` rules. Relates to #6646 [1]: https://developer.mozilla.org/en-US/docs/Web/Events/DOMContentLoaded [2]: https://developer.mozilla.org/en-US/docs/Web/Events/load [3]: https://developers.google.com/web/fundamentals/performance/user-centric-performance-metrics
145 lines
3.5 KiB
JavaScript
145 lines
3.5 KiB
JavaScript
/* MOCK DEV
|
|
*
|
|
* This is a utility module.
|
|
* It initializes a minimalist browserifiable project
|
|
* that contains the Metamask UI, with a local background process.
|
|
*
|
|
* Includes a state reset button for restoring to initial state.
|
|
*
|
|
* This is a convenient way to develop and test the plugin
|
|
* without having to re-open the plugin or even re-build it.
|
|
*/
|
|
|
|
const render = require('react-dom').render
|
|
const h = require('react-hyperscript')
|
|
const Root = require('../ui/app/pages')
|
|
const configureStore = require('../ui/app/store/store')
|
|
const actions = require('../ui/app/store/actions')
|
|
const states = require('./states')
|
|
const backGroundConnectionModifiers = require('./backGroundConnectionModifiers')
|
|
const Selector = require('./selector')
|
|
const MetamaskController = require('../app/scripts/metamask-controller')
|
|
const firstTimeState = require('../app/scripts/first-time-state')
|
|
const ExtensionPlatform = require('../app/scripts/platforms/extension')
|
|
const noop = function () {}
|
|
|
|
const log = require('loglevel')
|
|
window.log = log
|
|
log.setLevel('debug')
|
|
|
|
//
|
|
// Query String
|
|
//
|
|
|
|
const qs = require('qs')
|
|
const routerPath = window.location.href.split('#')[1]
|
|
let queryString = {}
|
|
let selectedView
|
|
|
|
if (routerPath) {
|
|
queryString = qs.parse(routerPath.split('?')[1])
|
|
}
|
|
|
|
selectedView = queryString.view || 'send new ui'
|
|
const firstState = states[selectedView]
|
|
updateQueryParams(selectedView)
|
|
|
|
function updateQueryParams (newView) {
|
|
queryString.view = newView
|
|
const params = qs.stringify(queryString)
|
|
const locationPaths = window.location.href.split('#')
|
|
const routerPath = locationPaths[1] || ''
|
|
const newPath = locationPaths[0] + '#' + routerPath.split('?')[0] + `?${params}`
|
|
|
|
if (window.location.href !== newPath) {
|
|
window.location.href = newPath
|
|
}
|
|
}
|
|
|
|
//
|
|
// MetaMask Controller
|
|
//
|
|
|
|
const controller = new MetamaskController({
|
|
// User confirmation callbacks:
|
|
showUnconfirmedMessage: noop,
|
|
unlockAccountMessage: noop,
|
|
showUnapprovedTx: noop,
|
|
platform: {},
|
|
// initial state
|
|
initState: firstTimeState,
|
|
})
|
|
global.metamaskController = controller
|
|
global.platform = new ExtensionPlatform()
|
|
|
|
//
|
|
// User Interface
|
|
//
|
|
|
|
actions._setBackgroundConnection(controller.getApi())
|
|
actions.update = function (stateName) {
|
|
selectedView = stateName
|
|
updateQueryParams(stateName)
|
|
const newState = states[selectedView]
|
|
return {
|
|
type: 'GLOBAL_FORCE_UPDATE',
|
|
value: newState,
|
|
}
|
|
}
|
|
|
|
function modifyBackgroundConnection (backgroundConnectionModifier) {
|
|
const modifiedBackgroundConnection = Object.assign({}, controller.getApi(), backgroundConnectionModifier)
|
|
actions._setBackgroundConnection(modifiedBackgroundConnection)
|
|
}
|
|
|
|
// parse opts
|
|
var store = configureStore(firstState)
|
|
|
|
// start app
|
|
startApp()
|
|
|
|
function startApp () {
|
|
const body = document.body
|
|
const container = document.createElement('div')
|
|
container.id = 'test-container'
|
|
body.appendChild(container)
|
|
|
|
render(
|
|
h('.super-dev-container', [
|
|
|
|
h('button', {
|
|
onClick: (ev) => {
|
|
ev.preventDefault()
|
|
store.dispatch(actions.update('terms'))
|
|
},
|
|
style: {
|
|
margin: '19px 19px 0px 19px',
|
|
},
|
|
}, 'Reset State'),
|
|
|
|
h(Selector, {
|
|
actions,
|
|
selectedKey: selectedView,
|
|
states,
|
|
store,
|
|
modifyBackgroundConnection,
|
|
backGroundConnectionModifiers,
|
|
}),
|
|
|
|
h('#app-content', {
|
|
style: {
|
|
height: '500px',
|
|
width: '360px',
|
|
boxShadow: 'grey 0px 2px 9px',
|
|
margin: '20px',
|
|
},
|
|
}, [
|
|
h(Root, {
|
|
store: store,
|
|
}),
|
|
]),
|
|
|
|
]
|
|
), container)
|
|
}
|