Firefox/Projects/Firefox Start/Snippet Service
The about:home snippet service is a simple, highly-cached content management service. It is intended to assemble and deliver content snippets to the about:home page in Firefox.
The content delivered is determined by details about the installation of Firefox requesting content - including mainly details about the browser's build, locale, platform, and distribution channel, but not the person using the browser.
Scalability vs content agility
A special note here: Although we can create and edit snippets in the service at any time, it may take up to 48 hours for changes in production to be reflected in browsers. This is because:
- Firefox only checks every 24 hours;
- and Zeus caches content from the service for 24 hours.
So, in the worst case, it's possible for those two time periods to stack up to a 2-day delay in content delivery.
The reason for this is that this service can be potentially hit by every Firefox user, so both the server and client sides are built to minimize the pressure on Mozilla resources.
about:home is a page built into Firefox 4 and above. By default, it fetches content from the production snippets service once every 24 hours. If content is available, it gets is stashed in localstorage for the page and displayed from there until the next fetch.
If no content is available, the browser has a built-in default set of snippets for display.
Source code for service
If you'd like to contribute or just run an instance, get the source from here:
See bug 592431 for historical context on this service.
Testing Snippets with Local or Stage Service
For testing against staging (ie. https://snippets.allizom.org) or a private development instance of the server (ie. http://localhost:8000), you'll need to tell Firefox to use these sources instead of the regular snippet service. There are two ways to accomplish this: manually and using the snippets switcher plugin.
Manually Updating Snippet Source
- Navigate to about:config
- Search for browser.aboutHomeSnippets.updateUrl
- Change the value accordingly. For the stage server, change the url to https://snippets.allizom.org.
- If you only want to retrieve a specific snippet, replace %NAME% (including the %s!) with the appropriate value.
- After saving the value, restart the browser.
- Navigate to about:home.
- Open the Web Developer > Web Console (ctrl+shift+k).
- If testing on Firefox <= 21.0, enter localStorage['snippets-last-update'] = 0 or if testing on Firefox >= 22.0 enter gSnippetsMap.clear();
- Refresh about:home. You should now see the new snippet.
Snippets Switcher Plugin
The Snippet Switcher is currently broken, do not use it! If you do, it may wipe out ```browser.aboutHomeSnippets.updateUrl``` and you'll have to reset it using the Recovery url below.
The snippets switcher plugin code is available here:
The xpi file is available here:
The plugin works by modifying the aboutHomeSnippets.updateUrl preference and updating localstorage variables accordingly. (See bug 603674 for more info).
If you've lost the original value of ```browser.aboutHomeSnippets.updateUrl```, reset it to:
Then, follow the Manual Update instructions above to preview your snippet.
Getting access to the production snippet service
This resource is highly protected, since it serves up content to all installations of Firefox. Access is limited to Mozilla employees, so file a bug or ask someone who knows about the snippet service (eg. email@example.com).
Managing snippet service content
All HTML content must also be well-formed XML.
Considerations for external media used in snippets
For example, a tool like The data: URI kitchen can be used to convert an image file into a data: URI.
If an external media resource is necessary, such as a video or an image too large for use as a data: URI, it will need to be hosted somewhere that can handle the potential traffic of every Firefox user requesting the URL. This means using a CDN or other high-capacity web host.
At present, localized snippets have no special handling in the service. They are just snippets with locale-specific client match rules. More work needs to be done here for bulk handling and grouping with an eye for l10n.
There are some undocumented tools available to help generate localized snippets and associated rules from an import manifest and translations attached to a bug.
The easiest way to do this right now is to:
- run a local copy of the snippet service;
- solicit locallizers to provide translations in text files as attachments on a bug
- see bug 636815, ensure locale included in parens in title - eg. (en-US)
- create an import manifest (no docs or spec on this yet);
- run `manage.py importfrombug` against the import manifest to generate snippets and rules in a local database;
- verify snippets were created as expected, export snippets (and rules) as JSON, upload the JSON to staging
Here are some raw pointers to code and examples of a recent import job:
- Bug 636815, with snippet translations in attachments
- Import manifest to generate snippets from translations and product locales
- Code that performs import, via `manage.py importfrombug imports/fx4-launch-import-bug-636815.json`
Client match rules
In order to get snippets served to appropriate locales and builds of Firefox, snippets are served using client match rules. These are rules matched against the URL of a request to the service, which should contain the following client details:
- Product name (eg. Firefox)
- Product version (eg. 4.0b12pre)
- App build id (eg. 20110214030347)
- Build target: (eg. Darwin_Universal-gcc3)
- Locale: (eg. en-US)
- Channel: (eg. nightly)
- OS version: (eg. Darwin 10.6.0)
- Distribution: (eg. default)
- Distribution version: (eg. default)
A client match rule defines criteria for one or more of the above attributes, optionally using a regular expression. One or more client match rule may be associated with any given snippet. When a request URL matches all associated rules, any associated snippets are included in the response. Note that for inclusion rules, all associated inclusion rules must match for the snippet to be included.
The exception is when a rule is flagged as an exclusion rule. In that case, a snippet is excluded from the response when an associated exclusion rule is matched, regardless of any other rules matching.
Service response as a whole
The response from the service is the result of snippets associated with client match rules triggered by the request URL, sorted by the sort order priority.
Keeping this in mind is important in considering what the response to any given client will look like. It means you can do things like:
- serve up common CSS and JS snippets for all locales
- include localized HTML content sandwiched between CSS and JS, using the sort order
- serve up multiple blocks of HTML, all hidden by CSS and selectively revealed by JS at random
Example snippets content
Here's an example JSON export of a set of client match rules and associated snippets:
You can take a look in a text editor, or try importing it into a private dev instance of the service.
In a nutshell, this demonstrates:
- CSS and JS across all locales to manage content styling and visibility
- snippets served up to just en-US / en-GB locales, other locales get the default snippets shipped with the browser
- multiple HTML snippets included, hidden with CSS and one randomly revealed with JS
- images encoded as data: URIs
- Snippet content is finalized, including a proofread and link-check before handed off to QA
- A "Please test Snippet X" bug is filed and assigned to firstname.lastname@example.org in the Other : Snippets : General component in Bugzilla
- QA follows the steps on https://wiki.mozilla.org/Firefox/Projects/Firefox_Start/Snippet_Service#Using_a_non-production_service_with_about:home against staging, with the Snippets Switcher add-on installed (en-US only, unless otherwise agreed upon)
- QA marks the bug Resolved FIXED when functionality is vetted
- Usual deployment process follows (is this documented? Can we document it here?)