Skip to content
This repository has been archived by the owner on May 10, 2019. It is now read-only.

Commit

Permalink
Refactored dialog_layout to use cachify for dev vs production.
Browse files Browse the repository at this point in the history
  • Loading branch information
ozten committed Feb 9, 2012
1 parent 97708c6 commit 2ff50ab
Show file tree
Hide file tree
Showing 3 changed files with 122 additions and 68 deletions.
14 changes: 14 additions & 0 deletions bin/browserid
Expand Up @@ -13,6 +13,7 @@ urlparse = require('urlparse'),
express = require('express');

const
cachify = require('connect-cachify'),
i18n = require('../lib/i18n.js'),
wsapi = require('../lib/wsapi.js'),
httputils = require('../lib/httputils.js'),
Expand Down Expand Up @@ -131,6 +132,19 @@ app.use(function(req, resp, next) {
return next();
});

app.use(cachify.setup({
production: config.get('use_minified_resources'),
js: views.js(config.get('supported_languages')),
css: {
"/production/dialog.css": [
"/css/common.css",
"/dialog/css/popup.css",
"/dialog/css/m.css"
]
}
}));


// #7 - perform response substitution to support local/dev/beta environments
// (specifically, this replaces URLs in responses, e.g. https://browserid.org
// with https://diresworb.org)
Expand Down
106 changes: 106 additions & 0 deletions lib/browserid/views.js
Expand Up @@ -9,6 +9,7 @@ logger = require('../logging.js').logger,
fs = require('fs'),
connect = require('connect'),
config = require('../configuration.js'),
und = require('../jwcrypto/underscore'),
util = require('util');

// all templated content, redirects, and renames are handled here.
Expand Down Expand Up @@ -216,3 +217,108 @@ exports.setup = function(app) {
next();
});
};

// Common to browserid.js dialog.js
var common1 = function (locale) {
return [
"/lib/jquery-1.7.1.min.js",
"/lib/winchan.js",
"/lib/underscore-min.js",
"/lib/vepbundle.js",
"/lib/ejs.js",
"/shared/javascript-extensions.js",
util.format("/i18n/%s/client.json", locale),
"/shared/gettext.js",
"/shared/browserid.js",
"/lib/hub.js",
"/lib/dom-jquery.js",
"/lib/module.js",
"/lib/jschannel.js",
"/shared/templates.js",
"/shared/renderer.js",
"/shared/class.js",
"/shared/mediator.js",
"/shared/tooltip.js",
"/shared/validation.js",
"/shared/helpers.js",
"/shared/screens.js",
"/shared/browser-support.js",
"/shared/wait-messages.js",
"/shared/error-messages.js",
"/shared/error-display.js",
"/shared/storage.js",
"/shared/xhr.js",
"/shared/network.js",
"/shared/provisioning.js",
"/shared/user.js"
];
};
// Common to browserid.js dialog.js

This comment has been minimized.

Copy link
@lloyd

lloyd Feb 10, 2012

Contributor

if this lives in code, how will the minification stuff get at it?

This comment has been minimized.

Copy link
@ozten

ozten Feb 10, 2012

Author Contributor

Short term - we can have our compress.sh and compress-locles.sh reuse views.js(langs) as config.

Long term - we could look at a node based build tool that also reuses this. If we go the route of connect-compiler then we can move this out of a build step into runtime, or whatever.

var common2 = [
"/shared/modules/page_module.js",
"/shared/modules/xhr_delay.js",
"/shared/modules/xhr_disable_form.js",
"/shared/modules/cookie_check.js"
];

This comment has been minimized.

Copy link
@ozten

ozten Feb 10, 2012

Author Contributor

Why is this so complicated you are thinking?

These lists common1, common2, etc are to accommodate our real world usage of these files in our top level templates.
This can probably be organized better and simplified, but I don't know enough about inter-script dependencies to do this.

Additionally, if we could simplify how we have all that code organized, it would make this simpler. This could all be cleaned up when we re-work compress.sh.


/**
* Cachify compatible mapping of JavaScript source and
* production build files.
*/
exports.js = function(langs) {
var js_files = {};
und.each(langs, function (lang) {
var locale = i18n.localeFrom(lang),
browserid_js,
dialog_js;

browserid_js = util.format("/production/%s/browserid.js", locale),
js_files[browserid_js] = und.flatten([
common1(locale),
common2,
[
"/pages/page_helpers.js",
"/pages/index.js",
"/pages/start.js",
"/pages/add_email_address.js",
"/pages/verify_email_address.js",
"/pages/forgot.js",
"/pages/manage_account.js",
"/pages/signin.js",
"/pages/signup.js"
]]);

dialog_js = util.format("/production/%s/dialog.js", locale);
js_files[dialog_js] = und.flatten([
common1(locale),
[
"/shared/command.js",
"/shared/history.js",
"/shared/state_machine.js"
],
common2,
[
"/dialog/resources/internal_api.js",
"/dialog/resources/helpers.js",
"/dialog/resources/state.js",

"/dialog/controllers/actions.js",
"/dialog/controllers/dialog.js",
"/dialog/controllers/authenticate.js",
"/dialog/controllers/forgot_password.js",
"/dialog/controllers/check_registration.js",
"/dialog/controllers/pick_email.js",
"/dialog/controllers/add_email.js",
"/dialog/controllers/required_email.js",
"/dialog/controllers/verify_primary_user.js",
"/dialog/controllers/provision_primary_user.js",
"/dialog/controllers/primary_user_provisioned.js",
"/dialog/controllers/email_chosen.js",

"/dialog/start.js"
]]);
});
return js_files;
};


70 changes: 2 additions & 68 deletions resources/views/dialog_layout.ejs
Expand Up @@ -12,13 +12,7 @@
<!--[if lt IE 9]>
<script src="/lib/html5shim.js"></script>
<![endif]-->
<% if (production) { %>
<link href="/production/dialog.css" rel="stylesheet" type="text/css">
<% } else { %>
<link href="/css/common.css" rel="stylesheet" type="text/css">
<link href="/dialog/css/popup.css" rel="stylesheet" type="text/css">
<link href="/dialog/css/m.css" rel="stylesheet" type="text/css">
<% } %>
<%- cachify_css('/production/dialog.css') %>
<link href="https://fonts.googleapis.com/css?family=Droid+Serif:400,400italic,700,700italic" rel="stylesheet" type="text/css">
<title><%= gettext('BrowserID') %></title>
</head>
Expand Down Expand Up @@ -52,67 +46,7 @@
</div>

<% if (useJavascript !== false) { %>
<% if (production) { %>
<script src="/production/<%= locale %>/dialog.js"></script>
<% } else { %>
<script src="/lib/jquery-1.7.1.min.js"></script>
<script src="/lib/winchan.js"></script>
<script src="/lib/underscore-min.js"></script>
<script src="/lib/vepbundle.js"></script>
<script src="/lib/ejs.js"></script>
<script src="/shared/javascript-extensions.js"></script>
<script src="/i18n/<%= locale %>/client.json"></script>
<script src="/shared/gettext.js"></script>
<script src="/shared/browserid.js"></script>
<script src="/lib/hub.js"></script>
<script src="/lib/dom-jquery.js"></script>
<script src="/lib/module.js"></script>
<script src="/lib/jschannel.js"></script>
<script src="/shared/templates.js"></script>
<script src="/shared/renderer.js"></script>
<script src="/shared/class.js"></script>
<script src="/shared/mediator.js"></script>
<script src="/shared/tooltip.js"></script>
<script src="/shared/validation.js"></script>
<script src="/shared/helpers.js"></script>
<script src="/shared/screens.js"></script>
<script src="/shared/browser-support.js"></script>
<script src="/shared/wait-messages.js"></script>
<script src="/shared/error-messages.js"></script>
<script src="/shared/error-display.js"></script>
<script src="/shared/storage.js"></script>
<script src="/shared/xhr.js"></script>
<script src="/shared/network.js"></script>
<script src="/shared/provisioning.js"></script>
<script src="/shared/user.js"></script>
<script src="/shared/command.js"></script>
<script src="/shared/history.js"></script>
<script src="/shared/state_machine.js"></script>
<script src="/shared/modules/page_module.js"></script>
<script src="/shared/modules/xhr_delay.js"></script>
<script src="/shared/modules/xhr_disable_form.js"></script>
<script src="/shared/modules/cookie_check.js"></script>
<script src="/dialog/resources/internal_api.js"></script>
<script src="/dialog/resources/helpers.js"></script>
<script src="/dialog/resources/state.js"></script>
<script src="/dialog/controllers/actions.js"></script>
<script src="/dialog/controllers/dialog.js"></script>
<script src="/dialog/controllers/authenticate.js"></script>
<script src="/dialog/controllers/forgot_password.js"></script>
<script src="/dialog/controllers/check_registration.js"></script>
<script src="/dialog/controllers/pick_email.js"></script>
<script src="/dialog/controllers/add_email.js"></script>
<script src="/dialog/controllers/required_email.js"></script>
<script src="/dialog/controllers/verify_primary_user.js"></script>
<script src="/dialog/controllers/provision_primary_user.js"></script>
<script src="/dialog/controllers/primary_user_provisioned.js"></script>
<script src="/dialog/controllers/email_chosen.js"></script>
<script src="/dialog/start.js"></script>
<% } %>
<%- cachify_js(util.format('/production/%s/dialog.js', locale)) %>
<% } %>
</body>
</html>

0 comments on commit 2ff50ab

Please sign in to comment.