Unless otherwise necessary (such as mobile development), the GitHub javascript codebase is based off jQuery. You can safely assume it will be included on every page.
- All jquery plugins should be prefixed with jquery, such as
jquery.facebox
- All github-specific jquery plugins should be prefixed with jquery.github. Like
jquery.github.repo_list.js
- All page-specific files (that only run on ONE page) should be prefixed with page.
page.billing.js
All javascript for the site should be put into a directory. Feel free to create new directories when it makes sense (gist, iphone, etc). There are a few directories that have special meanings:
common
- Contains all files that are used and shared between the main site and sub-sites (like gist)rogue
- Files that are directly called by individual pages. Use for large libraries that are only used on one (or a very few) pages.dev
- Files that are hosted elsewhere (such as google) that you will need if you do not have an internet connection.
Inside of each directory, you should note the difference between plugins and files where possible and split them into different directories (see github
).
On deploy, each top level directory is bundled into a compressed file. Any files that are inside the directory (and it's subfolders) will be bundled into one file and available at bundle_[directory].js
If you would like to include a bundle in your Rails templates, you reference bundles or individual files using the javascript_bundle
and javascript_dev
helpers.
javascript_dev ['jquery', 'http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js']
javascript_bundle 'common', 'github', 'rogue/s3_upload'
In production, this will include:
http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js
in production.bundle_common.js
bundle_github.js
rogue/s3_upload.js
In development, this will include:
dev/jquery.js
- All javascripts inside of the
common
directory - All javascripts inside the
github
directory rogue/s3_upload.js
What about pre-processors, like CoffeeScript or SASS?