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

Fix #736: Drop xorigin.js and dependencies.js to reduce startup time #741

Closed
wants to merge 8 commits into from
2 changes: 0 additions & 2 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,6 @@ module.exports = function (grunt) {
cwd: 'src/',
src: [
'nls/{,*/}*.js',
'xorigin.js',
'dependencies.js',
'thirdparty/github-markdown.css',
'hosted.*',
// XXXBramble: we don't use src/config.json like Brackets does,
Expand Down
60 changes: 0 additions & 60 deletions src/dependencies.js

This file was deleted.

14 changes: 9 additions & 5 deletions src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@
*/
outline: 1px solid transparent;
}
#iframe-warning {
visibility: hidden;
padding: 20px;
}

@-webkit-keyframes sk-rotatePlane {
0% {
Expand Down Expand Up @@ -100,9 +104,6 @@

<!-- NOTE: All scripts must be external for Chrome App support: http://developer.chrome.com/apps/app_csp.html -->

<!-- Warn about failed cross origin requests in Chrome -->
<script type="application/javascript" src="xorigin.js"></script>

<!--(if target dev)><!-->
<link rel="stylesheet" type="text/css" href="thirdparty/CodeMirror/lib/codemirror.css">
<link rel="stylesheet/less" type="text/css" href="styles/bramble.less">
Expand All @@ -117,6 +118,11 @@
-->
<div id="spinner-container">
<div class="sk-spinner sk-spinner-rotating-plane"></div>
<div id="iframe-warning">
<h1>Bramble must be hosted</h1>
<p>Oops! Bramble was loaded directly, outside of an iframe. For security it must be hosted in an iframe.</p>
<p>For local development, you can run Bramble in an iframe by using <a href="hosted.html">hosted.html</a> instead of <a href="index.html">index.html</a>.</p>
</div>
</div>

<!-- HTML content is dynamically loaded and rendered by brackets.js.
Expand All @@ -139,7 +145,5 @@
<script src="thirdparty/require.min.js" data-main="main"></script>
<!-- endbuild -->

<!-- Verify that all dependencies are loaded. -->
<script src="dependencies.js"></script>
</body>
</html>
164 changes: 90 additions & 74 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,105 +29,121 @@ require.config({
// Disable module loading timeouts, due to the size of what we load
waitSeconds: 0,
paths: {
"text" : "thirdparty/text/text",
"i18n" : "thirdparty/i18n/i18n",
"react" : "thirdparty/react",
"text": "thirdparty/text/text",
"i18n": "thirdparty/i18n/i18n",
"react": "thirdparty/react",

// The file system implementation. Change this value to use different
// implementations (e.g. cloud-based storage).
"fileSystemImpl" : "filesystem/impls/filer/FilerFileSystem",
"fileSystemImpl": "filesystem/impls/filer/FilerFileSystem",

// In various places in the code, it's useful to know if this is a dev vs. prod env.
// See Gruntfile for prod override of this to config.prod.js.
"envConfig" : "bramble/config/config.dev"
"envConfig": "bramble/config/config.dev"
},
map: {
"*": {
"thirdparty/CodeMirror2": "thirdparty/CodeMirror",
"thirdparty/react": "react"
"thirdparty/react": "react"
}
}
});

if (window.location.search.indexOf("testEnvironment") > -1) {
require.config({
paths: {
"preferences/PreferencesImpl": "../test/TestPreferencesImpl"
},
locale: "en" // force English (US)
if (window.location === window.parent.location) {
$('#iframe-warning').css({
'visibility': 'visible'
});
$('.sk-spinner-rotating-plane.sk-spinner').css({
'visibility': 'hidden'
});

} else {
/**
* hack for r.js optimization, move locale to another config call
*
* Use custom brackets property until CEF sets the correct navigator.language
* NOTE: When we change to navigator.language here, we also should change to
* navigator.language in ExtensionLoader (when making require contexts for each
* extension).
*/
var urlLocale = window.location.search && /locale=([^&]+)&?/.exec(window.location.search);
urlLocale = urlLocale && urlLocale[1] && urlLocale[1].toLowerCase();

require.config({
locale: urlLocale || (typeof (brackets) !== "undefined" ? brackets.app.language : window.navigator.language)
});
}
if (window.location.search.indexOf("testEnvironment") > -1) {
require.config({
paths: {
"preferences/PreferencesImpl": "../test/TestPreferencesImpl"
},
locale: "en" // force English (US)
});
} else {
/**
* hack for r.js optimization, move locale to another config call
*
* Use custom brackets property until CEF sets the correct navigator.language
* NOTE: When we change to navigator.language here, we also should change to
* navigator.language in ExtensionLoader (when making require contexts for each
* extension).
*/
var urlLocale = window.location.search && /locale=([^&]+)&?/.exec(window.location.search);
urlLocale = urlLocale && urlLocale[1] && urlLocale[1].toLowerCase();

/**
* Service Worker offline cache registration. The bramble-sw.js file
* is generated by Grunt as part of a dist/ build, and will not do anything
* in dev builds.
*/
if ('serviceWorker' in window.navigator) {
window.navigator.serviceWorker.register('bramble-sw.js').then(function(reg) {
"use strict";
require.config({
locale: urlLocale || (typeof (brackets) !== "undefined" ? brackets.app.language : window.navigator.language)
});

function sendMessage(data) {
parent.postMessage(JSON.stringify(data), "*");
}
}

// Let the parent frame know that we have updates in the SW cache.
function updatesAvailable() {
sendMessage({ type: 'Bramble:updatesAvailable' });
}
/**
* Service Worker offline cache registration. The bramble-sw.js file
* is generated by Grunt as part of a dist/ build, and will not do anything
* in dev builds.
*/
if ('serviceWorker' in window.navigator) {
window.navigator.serviceWorker.register('bramble-sw.js').then(function (reg) {
"use strict";

// Let the parent frame know that we've cached content for offline loading.
function offlineReady() {
sendMessage({ type: 'Bramble:offlineReady' });
}
function sendMessage(data) {
parent.postMessage(JSON.stringify(data), "*");
}

// Let the parent frame know that we have updates in the SW cache.
function updatesAvailable() {
sendMessage({ type: 'Bramble:updatesAvailable' });
}

reg.onupdatefound = function() {
var installingWorker = reg.installing;
// Let the parent frame know that we've cached content for offline loading.
function offlineReady() {
sendMessage({ type: 'Bramble:offlineReady' });
}

installingWorker.onstatechange = function() {
switch (installingWorker.state) {
case 'installed':
if (window.navigator.serviceWorker.controller) {
updatesAvailable();
} else {
offlineReady();
reg.onupdatefound = function () {
var installingWorker = reg.installing;

installingWorker.onstatechange = function () {
switch (installingWorker.state) {
case 'installed':
if (window.navigator.serviceWorker.controller) {
updatesAvailable();
} else {
offlineReady();
}
break;
case 'redundant':
console.error('[Bramble] The installing service worker became redundant.');
break;
}
break;
case 'redundant':
console.error('[Bramble] The installing service worker became redundant.');
break;
}
};
};
};
}).catch(function(e) {
"use strict";
console.error('[Bramble] Error during service worker registration:', e);
});
}
}).catch(function (e) {
"use strict";
console.error('[Bramble] Error during service worker registration:', e);
});
}


define(function (require) {
"use strict";
// XXXBramble: We host the filesystem in the hosting, parent window. Make sure
// we're loaded within an iframe, and warn if not.

// XXXBramble: get the filesystem loading ASAP for connection with parent window
require(["filesystem/impls/filer/RemoteFiler"], function(RemoteFiler) {
RemoteFiler.init();
// Load the brackets module. This is a self-running module that loads and
// runs the entire application.
require(["brackets"]);
define(function (require) {
"use strict";

// XXXBramble: get the filesystem loading ASAP for connection with parent window
require(["filesystem/impls/filer/RemoteFiler"], function (RemoteFiler) {
RemoteFiler.init();
// Load the brackets module. This is a self-running module that loads and
// runs the entire application.
require(["brackets"]);
});
});
});
}
74 changes: 0 additions & 74 deletions src/xorigin.js

This file was deleted.