Skip to content

Commit

Permalink
refactor: use public accessors for network records
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickhulce committed Jan 31, 2017
1 parent f9698f0 commit 6406bf3
Show file tree
Hide file tree
Showing 11 changed files with 1,168 additions and 1,168 deletions.
2 changes: 1 addition & 1 deletion lighthouse-core/audits/dobetterweb/uses-http2.js
Expand Up @@ -52,7 +52,7 @@ class UsesHTTP2Audit extends Audit {

// Filter requests that are on the same host as the page and not over h2.
const resources = networkRecords.filter(record => {
const requestHost = new URL(record._url).host;
const requestHost = new URL(record.url).host;
const sameHost = requestHost === finalHost;
const notH2 = /HTTP\/[01][\.\d]?/i.test(record.protocol);
return sameHost && notH2;
Expand Down
2 changes: 1 addition & 1 deletion lighthouse-core/gather/computed/critical-request-chains.js
Expand Up @@ -61,7 +61,7 @@ class CriticalRequestChains extends ComputedArtifact {

const flattenRequest = request => {
return {
url: request._url,
url: request.url,
startTime: request.startTime,
endTime: request.endTime,
responseReceivedTime: request.responseReceivedTime,
Expand Down
16 changes: 8 additions & 8 deletions lighthouse-core/gather/gatherers/dobetterweb/optimized-images.js
Expand Up @@ -73,21 +73,21 @@ class OptimizedImages extends Gatherer {
static filterImageRequests(pageUrl, networkRecords) {
const seenUrls = new Set();
return networkRecords.reduce((prev, record) => {
if (seenUrls.has(record._url)) {
if (seenUrls.has(record.url)) {
return prev;
}

seenUrls.add(record._url);
const isOptimizableImage = /image\/(png|bmp|jpeg)/.test(record._mimeType);
const isSameOrigin = URL.hostsMatch(pageUrl, record._url);
const isBase64DataUri = /^data:.{2,40}base64\s*,/.test(record._url);
seenUrls.add(record.url);
const isOptimizableImage = /image\/(png|bmp|jpeg)/.test(record.mimeType);
const isSameOrigin = URL.hostsMatch(pageUrl, record.url);
const isBase64DataUri = /^data:.{2,40}base64\s*,/.test(record.url);

if (isOptimizableImage && (isSameOrigin || isBase64DataUri)) {
prev.push({
isBase64DataUri,
url: record._url,
mimeType: record._mimeType,
resourceSize: record._resourceSize,
url: record.url,
mimeType: record.mimeType,
resourceSize: record.resourceSize,
});
}

Expand Down
Expand Up @@ -94,17 +94,17 @@ function filteredAndIndexedByUrl(networkRecords) {
const isParserGenerated = record._initiator.type === 'parser';
// A stylesheet only blocks script if it was initiated by the parser
// https://html.spec.whatwg.org/multipage/semantics.html#interactions-of-styling-and-scripting
const isParserScriptOrStyle = /(css|script)/.test(record._mimeType) && isParserGenerated;
const isFailedRequest = record._failed;
const isHtml = record._mimeType && record._mimeType.includes('html');
const isParserScriptOrStyle = /(css|script)/.test(record.mimeType) && isParserGenerated;
const isFailedRequest = record.failed;
const isHtml = record.mimeType && record.mimeType.includes('html');

// Filter stylesheet, javascript, and html import mimetypes.
// Include 404 scripts/links generated by the parser because they are likely blocking.
if (isHtml || isParserScriptOrStyle || (isFailedRequest && isParserGenerated)) {
prev[record._url] = {
transferSize: record._transferSize,
startTime: record._startTime,
endTime: record._endTime
prev[record.url] = {
transferSize: record.transferSize,
startTime: record.startTime,
endTime: record.endTime
};
}

Expand Down
4 changes: 2 additions & 2 deletions lighthouse-core/gather/gatherers/image-usage.js
Expand Up @@ -74,8 +74,8 @@ class ImageUsage extends Gatherer {
afterPass(options, traceData) {
const driver = this.driver = options.driver;
const indexedNetworkRecords = traceData.networkRecords.reduce((map, record) => {
if (/^image/.test(record._mimeType)) {
map[record._url] = {
if (/^image/.test(record.mimeType)) {
map[record.url] = {
url: record.url,
resourceSize: record.resourceSize,
startTime: record.startTime,
Expand Down
2 changes: 1 addition & 1 deletion lighthouse-core/gather/gatherers/offline.js
Expand Up @@ -26,7 +26,7 @@ class Offline extends Gatherer {

afterPass(options, tracingData) {
const navigationRecord = tracingData.networkRecords.filter(record => {
return URL.equalWithExcludedFragments(record._url, options.url) &&
return URL.equalWithExcludedFragments(record.url, options.url) &&
record._fetchedViaServiceWorker;
}).pop(); // Take the last record that matches.

Expand Down

0 comments on commit 6406bf3

Please sign in to comment.