This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.

Bug 24387 - Expose media queries to workers
Summary: Expose media queries to workers
Status: NEW
Alias: None
Product: CSS
Classification: Unclassified
Component: CSSOM View (show other bugs)
Version: unspecified
Hardware: PC All
: P2 normal
Target Milestone: ---
Assignee: Simon Pieters
QA Contact: public-css-bugzilla
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-01-24 23:22 UTC by Jonas Sicking (Not reading bugmail)
Modified: 2014-10-02 19:28 UTC (History)
1 user (show)

See Also:


Attachments

Description Jonas Sicking (Not reading bugmail) 2014-01-24 23:22:02 UTC
We should expose the media-queries API to Web Workers.

This is going to be especially important for ServiceWorkers who will want to decide which resources to download based on properties of the client.

Since workers don't have a window, we can only expose a subset of the properties. I.e. properties that are specific to the hardware and not dependent on the current window size etc.

Things like device-resolution is especially interesting since most of the time that is hardware dependent. However the user might plug in additional monitors which might have a different resolution. Not sure what the answer is here.
Comment 1 Simon Pieters 2014-01-25 20:30:15 UTC
Can you elaborate on the use cases? Which resources? Which properties?

For instance, if a use case is to evaluate which image to download given a set of URLs and associated media queries, it seems like a requirement to be able to evaluate the viewport width media queries.
Comment 2 Jonas Sicking (Not reading bugmail) 2014-01-27 18:53:27 UTC
One of the central features of Service Workers is to pre-download resources that a website will need such that when they are needed they are already available cached when needed. The goal is both to make online faster and offline possible.

As part of that, the ServiceWorker receives events when the UA detects that a new version of the ServiceWorker (and thus likely of the website) is available. This way the ServiceWorker can download the assets needed by that version.

It's up to the UA to choose when it's looking for updated versions of the SW. It's also up to the UA when to launch the SW and fire an event to it letting it know that it is a good time to download new needed resources.

This might happen when no pages for the website is open. I.e. a UA can (and implementations have indicated that they will) check for updates for websites that the user uses a lot even if the user isn't currently using the website.

In some instances the SW will likely want to develop different resources based on the physical capabilities of the hardware that the UA is running on. So for example when a new version of a website is released, the new version might use a couple of images that are available in multiple different resolutions. The SW would then want to choose which images to predownload and cache based on things like screen size and screen resolution.

Hence it needs a way to ask about those things. When the website is up and running it could simply use postMessage to talk to JS running in a Window which could then use the normal media queries API. However if the website isn't currently open in any Window, that doesn't work. (And arguably it's an awkward solution even when possible).