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

Allow advanced users to enforce JSON response types in XHRs. #331

Merged
merged 1 commit into from
Apr 16, 2015

Conversation

nicksay
Copy link
Contributor

@nicksay nicksay commented 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 #317.

spf.debug.debug('nav.request.handleCompleteFromXHR_ ',
url, {'extra': chunking.extra, 'complete': xhr.responseText});
spf.debug.debug('nav.request.handleCompleteFromXHR_ ', url,
xhr.responseType == 'json' ?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line is a bit excessive. Can you determine the correct response object to log on another line and pass it in?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@DavidCPhillips
Copy link
Contributor

LGTM

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 force-pushed the response-type-json branch from 20473f5 to 027fc2c Compare April 16, 2015 18:38
nicksay added a commit that referenced this pull request Apr 16, 2015
Allow advanced users to enforce JSON response types in XHRs.
@nicksay nicksay merged commit b6d08d5 into youtube:master Apr 16, 2015
@nicksay nicksay deleted the response-type-json branch April 16, 2015 22:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use XHR2 responseType = "json" when possible
2 participants