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

feat: enhanced display URLs #1793

Merged
merged 8 commits into from
Mar 2, 2017
Merged

feat: enhanced display URLs #1793

merged 8 commits into from
Mar 2, 2017

Conversation

patrickhulce
Copy link
Collaborator

@ebidel brought up that a lot of the byte efficiency audits can look like buggy duplicates because the query strings are hidden. This PR adds options to URL.getDisplayName that

  • Makes removing the query string optional and elides long query strings
  • Makes removing the host optional
  • Makes the path split optional

In the examples below the duplicate dbw_tester is because of an XHR that actually requests it a second time.
Before
image

After
image

* @return {string}
*/
URL.getDisplayName = function getDisplayName(url) {
URL.getDisplayName = function getDisplayName(url, options) {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: options = {} default arg.

works as you have it though.

options = Object.assign({
pathParts: 2,
removeQuery: true,
removeHost: true,
Copy link
Contributor

Choose a reason for hiding this comment

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

cant remember where we landed on trailing ,. Anyone?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I've been slowly sneaking them in over time as I touch files :) I'm in favor of always enforcing for cleaner diffs

@@ -0,0 +1 @@
{"_":["https://www.theverge.com/"],"help":false,"version":false,"disable-storage-reset":false,"disableStorageReset":false,"disable-device-emulation":true,"disableDeviceEmulation":true,"disable-cpu-throttling":true,"disableCpuThrottling":true,"disable-network-throttling":true,"disableNetworkThrottling":true,"save-assets":false,"saveAssets":false,"save-artifacts":false,"saveArtifacts":false,"list-all-audits":false,"listAllAudits":false,"list-trace-categories":false,"listTraceCategories":false,"perf":false,"skip-autolaunch":false,"skipAutolaunch":false,"select-chrome":false,"selectChrome":false,"verbose":false,"quiet":false,"interactive":true,"output":"pretty","output-path":"stdout","outputPath":"stdout","port":9222,"max-wait-for-load":25000,"maxWaitForLoad":25000,"$0":"lighthouse-cli/index.js","logLevel":"info"}
Copy link
Contributor

Choose a reason for hiding this comment

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

newline

Copy link
Contributor

Choose a reason for hiding this comment

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

wait what are these files?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

uh I have no idea...something must have disappeared from .gitignore

pathParts: 2,
removeQuery: true,
removeHost: true,
}, options)
Copy link
Contributor

Choose a reason for hiding this comment

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

;

// And grab the last two parts.
.split('/').slice(-2).join('/');
name = parsed.pathname;
const parts = name.split('/')
Copy link
Contributor

Choose a reason for hiding this comment

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

;

name = `${parsed.host}/${name.replace(/^\//, '')}`;
}
if (!options.removeQuery) {
name = `${name}${parsed.search}`
Copy link
Contributor

Choose a reason for hiding this comment

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

;

if (name.length > MAX_LENGTH && name.includes('?')) {
const prevName = name;
// Try to leave the first query parameter intact
name = name.replace(/\?([^=]*)(=)?.*/, '?$1$2\u2026')
Copy link
Contributor

Choose a reason for hiding this comment

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

;


// Remove it all if it's still too long
if (name.length > MAX_LENGTH) {
name = name.replace(/\?.*/, '?\u2026')
Copy link
Contributor

Choose a reason for hiding this comment

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

; all day long

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

haha sorry you jumped the gun on my lint/tests commit :P (did a lot of personal work this weekend, and I use no semis)

name = parsed.pathname;
const parts = name.split('/');
if (options.pathParts && parts.length > options.pathParts) {
name = '/\u2026/' + parts.slice(-1 * options.pathParts).join('/');
Copy link
Contributor

Choose a reason for hiding this comment

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

i keep thinking pathParts is a split array. What about numParts?

Copy link
Contributor

Choose a reason for hiding this comment

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

Do you think the part prefix is worth it? It takes up realestate that we otherwise could show more of the URL.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think it's confusing the way it's presented now and I use lighthouse everyday haha, so I'm in favor of displaying an ellipsis everywhere we remove characters. I'm cool with getting rid of the double/ if it's too much

Copy link
Contributor

Choose a reason for hiding this comment

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

Yea. Remove the first '/' would be good. Otherwise, it looks like a relative URL, up a directory.

name = parsed.pathname;
const parts = name.split('/');
if (options.numPathParts && parts.length > options.numPathParts) {
name = '\u2026' + parts.slice(-1 * options.numPathParts).join('/');
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: lots of \u2026 everywhere. Is that worth factoring out into a const var?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yeah good call

@@ -140,7 +140,7 @@ class UnusedCSSRules extends Audit {
const contentPreview = UnusedCSSRules.determineContentPreview(stylesheetInfo.content);
url = '*inline*```' + contentPreview + '```';
} else {
url = URL.getDisplayName(url);
url = URL.getDisplayName(url, {removeQuery: false});
Copy link
Member

Choose a reason for hiding this comment

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

false as an overriding option is kinda awkward. (just like on the CLI)

how about preserveQuery: true so we can flip these.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

good call, done

@paulirish paulirish merged commit 6080e6b into master Mar 2, 2017
@paulirish paulirish deleted the get_display_name_options branch March 2, 2017 03:55
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.

None yet

3 participants