Skip to content

Requireable Javascript #128

@jlbooker

Description

@jlbooker

Let's take a day and make all of Javascript require-able using require.js.

There are several parts to this:

  1. Go through very javascript module and make it adhere to the AMD standard.
  2. Modify the javascript() and javascriptMod() methods to add the requested javascript module to a list.
  3. Modify Layout class to use the list from calls to javascript() and javascriptMod() to generate the config file (per page) that require.js needs.

Pros:

  • Quickly gets us out of javascript dependency/ordering problems.
  • Allows us to start participating in the AMD standard, which looks to be the state of the art

Cons:

  • Doesn't minify/compile javascript as much as absolutely possible. Each JS that is loaded via require will still trigger a separate HTTP request, which is sub-optimal. However, those files will be able to be consistently cached (since they won't vary by page) on the client browser. The impact will be greatest on first page load, but should be minimal after that.
Bonus

Move all inclusion of JS to the bottom of the page, just before the closing </body> tag (for page performance). But.. This will break any in-line js included in body.js files, or directly in page templates, so it needs to be done carefully and with great testing.

┆Issue is synchronized with this Asana task

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions