Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use XHR2 responseType = "json" when possible #317

Closed
nicksay opened this issue Mar 16, 2015 · 1 comment · Fixed by #331
Closed

Use XHR2 responseType = "json" when possible #317

nicksay opened this issue Mar 16, 2015 · 1 comment · Fixed by #331

Comments

@nicksay
Copy link
Contributor

nicksay commented Mar 16, 2015

Chrome and Firefox support setting responseType = "json" on XMLHttpRequest objects: https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest#Properties

This allows the browser to parse JSON on a separate thread before returning. Since every request always does a full parse for error-handling (

// Always attempt a full parse with error handling.
) using the value provided by responseType = "json" may reduce main thread contention slightly.

This is primarily a concern when loading very large responses.

@nicksay
Copy link
Contributor Author

nicksay commented Apr 8, 2015

Investigated this a little more:

Positive

  • JSON parsing done off of the main thread
  • Reduces CPU contention; leads to less interference with ongoing animations, etc

Negative

  • No accessible errors for malformed responses (i.e. JSON syntax problems)
    • The xhr.response value is null
    • No stack trace, etc
  • No support for processing chunked responses on-the-fly (i.e. pseudo-streaming)
    • Using responseType = "json" will prevent sites from effectively using multipart responses.

nicksay added a commit to nicksay/spfjs that referenced this issue Apr 13, 2015
Add support for setting the XHR `responseType` property to `"json"`.  This
defines the response data as JSON and prevents the browser from handling other
types of data.  It allows JSON parsing to be done off of the main thread,
reducing CPU contention that can happen with large responses and low-power
devices; this can yield smoother animations during navigation, for example.
However, it prevents processing chunked responses on-the-fly (i.e.
pseudo-streaming), effectively eliminating most of the benefits of multipart
responses.  Guard this behavior behind an "advanced" config flag and provide
no default to prevent accidental usage.  Setting `advanced-response-type-json`
to `true` will enable the feature.

Closes youtube#317.
nicksay added a commit to nicksay/spfjs that referenced this issue Apr 13, 2015
Add support for setting the XHR `responseType` property to `"json"`.  This
defines the response data as JSON and prevents the browser from handling other
types of data.  It allows JSON parsing to be done off of the main thread,
reducing CPU contention that can happen with large responses and low-power
devices; this can yield smoother animations during navigation, for example.
However, it prevents processing chunked responses on-the-fly (i.e.
pseudo-streaming), effectively eliminating most of the benefits of multipart
responses.  Guard this behavior behind an "advanced" config flag and provide
no default to prevent accidental usage.  Setting `advanced-response-type-json`
to `true` will enable the feature.

Closes youtube#317.
nicksay added a commit to nicksay/spfjs that referenced this issue Apr 14, 2015
nicksay added a commit to nicksay/spfjs that referenced this issue Apr 14, 2015
Add support for setting the XHR `responseType` property to `"json"`.  This
defines the response data as JSON and prevents the browser from handling other
types of data.  It allows JSON parsing to be done off of the main thread,
reducing CPU contention that can happen with large responses and low-power
devices; this can yield smoother animations during navigation, for example.
However, it prevents processing chunked responses on-the-fly (i.e.
pseudo-streaming), effectively eliminating most of the benefits of multipart
responses.  Guard this behavior behind an "advanced" config flag and provide
no default to prevent accidental usage.  Setting `advanced-response-type-json`
to `true` will enable the feature.

Closes youtube#317.
nicksay added a commit to nicksay/spfjs that referenced this issue Apr 16, 2015
Add support for setting the XHR `responseType` property to `"json"`.  This
defines the response data as JSON and prevents the browser from handling other
types of data.  It allows JSON parsing to be done off of the main thread,
reducing CPU contention that can happen with large responses and low-power
devices; this can yield smoother animations during navigation, for example.
However, it prevents processing chunked responses on-the-fly (i.e.
pseudo-streaming), effectively eliminating most of the benefits of multipart
responses.  Guard this behavior behind an "advanced" config flag and provide
no default to prevent accidental usage.  Setting `advanced-response-type-json`
to `true` will enable the feature.

Closes youtube#317.
@nicksay nicksay added this to the SPF 23 milestone Oct 1, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant