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

report(redirects): reformat results, incl all requests and wasted time, #3492

Merged
merged 4 commits into from
Oct 31, 2017

Conversation

paulirish
Copy link
Member

@paulirish paulirish commented Oct 6, 2017

Changes:
  • The cost of each redirect is shown next to the new/redirected URL rather than initial URL. (Makes more sense to my brain). This also means we now show the final URL in the table, whereas before it wasn't there.
  • The very first initial url is shown for completeness.
  • (If there's just 1 redirect we currently pass them. Nothing changes here.)
  • All costs of redirects are kept and summed. We don't skip the first one.
  • Even if there's 1 redirect and you pass, we will still show the cost of the redirects to be clear.
  • I updated the test cases to be slightly more realistic.
screenshots

failing with 2 redirects:
image

passing with 1 redirect:
image

passing with 0 redirects:
image


// Only create a table (with the initial request) if there are > 1 redirects
if (!initialRequest) {
if (redirectRequests.length > 1) {
Copy link
Member Author

Choose a reason for hiding this comment

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

This >1 and a === 2 below could instead use a ACCEPTED_REDIRECTS const if folks prefer.

startTime: 17,
url: 'http://exampel.com/',
Copy link
Collaborator

@wardpeet wardpeet Oct 6, 2017

Choose a reason for hiding this comment

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

typo example.com?

Copy link
Member Author

Choose a reason for hiding this comment

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

this was deliberate. :)

Copy link
Collaborator

@wardpeet wardpeet left a comment

Choose a reason for hiding this comment

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

Looks good, thanks for cleaning up! Really appreciate it! 🥇
Just a few remarks about urls and spelling 😄

startTime: 12,
url: 'https://m.example.com/',
},
],
};

const FAILING_TWO_REDIRECTS = {
startTime: 446.286,
url: 'http://lisairish.com/',
Copy link
Collaborator

Choose a reason for hiding this comment

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

perhaps better to just use example.com as an url so it's consistent with the rest?

Or is this a marketing stunt for your mom's website? 😆

Copy link
Member Author

Choose a reason for hiding this comment

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

Well i tested this with these actual URLs, which have this set of redirects setup.

{key: 'wastedMs', itemType: 'text', text: 'Time for Redirect'},
];
const details = Audit.makeTableDetails(headings, pageRedirects);

return {
score: UnusedBytes.scoreForWastedMs(totalWastedMs),
// We award a passing grade if you only have 1 redirect
score: redirectRequests.length === 2 ? 100 : UnusedBytes.scoreForWastedMs(totalWastedMs),
Copy link
Collaborator

Choose a reason for hiding this comment

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

if totalWastedMs === 0 scoreForWastedMs doesn't already give you a 100?

Copy link
Member Author

Choose a reason for hiding this comment

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

With the new logic you can get totalWastedMs > 0 and still get a passing grade. Take http://www.lisairish.com which i was seeing it take 500ms to redirect to https://www.lisairish.com. We should still tell them about the 500ms even if we pass them.

Copy link
Collaborator

Choose a reason for hiding this comment

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

could we add a passing test case for a resource with 0 redirects too? I had to pause for a second on this, alternatively switch to redirectRequests.length <= 2

Copy link
Member Author

Choose a reason for hiding this comment

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

already have passing test case for 0 redirects.
changed to <= 2.

Copy link
Member

@brendankenny brendankenny left a comment

Choose a reason for hiding this comment

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

need to update the smoke test expectations for the additional URL in the details list. Not sure about the other failure though...was that expected?

@brendankenny
Copy link
Member

was that expected?

ah, yes, it was:

All costs of redirects are kept and summed. We don't skip the first one.

// We allow 1 redirect (www. => m.)
if (i > 1) {
totalWastedMs += wastedMs;
for (let i = 0; i < redirectRequests.length; i++) {
Copy link
Member

Choose a reason for hiding this comment

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

the if (!initialRequest) part of this ends up being a little confusing. What about pulling it out, something like

let totalWastedMs = 0;
const pageRedirects = [];

if (redirectRequests.length > 1) {
  pageRedirects.push({
    url: `(Initial: ${redirectRequests[0].url})`,
    wastedMs: 'n/a',
  });
}

for (let i = 1; i < redirectRequests.length; i++) {
  const initialRequest = redirectRequests[i - 1];
  const redirectedRequest = redirectRequests[i];

  const wastedMs = (redirectedRequest.startTime - initialRequest.startTime) * 1000;
  totalWastedMs += wastedMs;

  pageRedirects.push({
    url: redirectedRequest.url,
    wastedMs: Util.formatMilliseconds(wastedMs, 1),
  });
}

(I believe that should be equivalent)

Copy link
Collaborator

Choose a reason for hiding this comment

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

+1

Copy link
Member Author

Choose a reason for hiding this comment

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

sg thx

@paulirish
Copy link
Member Author

updated! @brendankenny ptal.

@paulirish paulirish changed the title Redirects audit: formatting report(redirects): reformat results, including all requests and wasted time Oct 9, 2017
@paulirish paulirish changed the title report(redirects): reformat results, including all requests and wasted time report(redirects): reformat results, incl all requests and wasted time Oct 9, 2017
@brendankenny
Copy link
Member

will you rebase to pick up the passive event listener fix?

Copy link
Member

@brendankenny brendankenny left a comment

Choose a reason for hiding this comment

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

ptal :)

@paulirish
Copy link
Member Author

@brendankenny thar u go

@paulirish paulirish changed the title report(redirects): reformat results, incl all requests and wasted time report(redirects) reformat results, incl all requests and wasted time Oct 26, 2017
@paulirish paulirish changed the title report(redirects) reformat results, incl all requests and wasted time report(redirects): reformat results, incl all requests and wasted time Oct 26, 2017
@paulirish paulirish changed the title report(redirects): reformat results, incl all requests and wasted time report(redirects): reformat results, incl all requests and wasted time. Oct 26, 2017
@paulirish paulirish changed the title report(redirects): reformat results, incl all requests and wasted time. report(redirects): reformat results, incl all requests and wasted time Oct 26, 2017
@paulirish paulirish changed the title report(redirects): reformat results, incl all requests and wasted time report(redirects): reformat results, incl all requests and wasted time, Oct 26, 2017
@paulirish paulirish changed the title report(redirects): reformat results, incl all requests and wasted time, report(redirects): reformat results, incl all requests and wasted time,. Oct 26, 2017
@paulirish paulirish changed the title report(redirects): reformat results, incl all requests and wasted time,. report(redirects): reformat results, incl all requests and wasted time, Oct 26, 2017
@paulirish paulirish changed the title report(redirects): reformat results, incl all requests and wasted time, report(redirects): reformat results, incl all requests and wasted time,. Oct 26, 2017
@paulirish paulirish changed the title report(redirects): reformat results, incl all requests and wasted time,. report(redirects): reformat results, incl all requests and wasted time, Oct 26, 2017
Copy link
Member

@brendankenny brendankenny left a comment

Choose a reason for hiding this comment

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

LGTM, sorry I missed your rebase!

@brendankenny
Copy link
Member

@patrickhulce if you have any last issues

assert.equal(output.details.items.length, 4);
assert.equal(output.rawValue, 17000);
});
});
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: add newline

Copy link
Collaborator

@patrickhulce patrickhulce left a comment

Choose a reason for hiding this comment

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

lgtm % nits

{key: 'wastedMs', itemType: 'text', text: 'Time for Redirect'},
];
const details = Audit.makeTableDetails(headings, pageRedirects);

return {
score: UnusedBytes.scoreForWastedMs(totalWastedMs),
// We award a passing grade if you only have 1 redirect
score: redirectRequests.length === 2 ? 100 : UnusedBytes.scoreForWastedMs(totalWastedMs),
Copy link
Collaborator

Choose a reason for hiding this comment

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

could we add a passing test case for a resource with 0 redirects too? I had to pause for a second on this, alternatively switch to redirectRequests.length <= 2

@paulirish paulirish merged commit fbe3fda into master Oct 31, 2017
@paulirish paulirish deleted the redirects-hax branch October 31, 2017 23:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants