Skip to content

Conversation

@FilipChalupa
Copy link
Contributor

Nové nastavení je rychlejší, protože spuštění stažení shapes nečeká na vykonání javascriptu a zároveň dává více informací browseru o tom, co jsou shapes za typ souboru, takže je může lépe cachovat.

(IE celé url v xlink:href nepodporuje, takže pro něj se dál používají staré shapes na základě detekce podle user agentu.)

Copy link
Contributor

@enzy enzy left a comment

Choose a reason for hiding this comment

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

I would prefer a sort of a feature detection approach instead. Import and execute when the primary method fails.
There were also other reasons (other than IE) not to use direct path but I can't remember it now.

@FilipChalupa
Copy link
Contributor Author

Same here, however, there isn't a way how to feature detect AFAIK.

Delayed import for IE only for a few lines of code is a bit overkill.

I've tested Chrome, Safari, Firefox, Edge, IE. All seem to work consistently.

Copy link
Contributor

@JirkaVebr JirkaVebr left a comment

Choose a reason for hiding this comment

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

I completely agree with @enzy that a feature detection based approach would have been preferable but much like @onset, I cannot think of any. 🙁 Can you, @enzy?

Also, now that shapes are being downloaded as an actual image, why don't we add something like <link rel="preload" as="image" href="/assets/shapes.svg"> (or whatever the appropriate value for as is)? I'd say that being able to start downloading early is the just about the main benefit of and motivation for this change so why not go even further? 🙂

@FilipChalupa
Copy link
Contributor Author

Also, now that shapes are being downloaded as an actual image, why don't we add something like <link rel="preload" as="image" href="/assets/shapes.svg"> (or whatever the appropriate value for as is)? I'd say that being able to start downloading early is the just about the main benefit of and motivation for this change so why not go even further? 🙂

Preloading is overoptimization in this case. Hard maintainability is not worth it. Browser can start downloading with first discovered shape in HTML. That can be a logo in header close to head tag where <link rel="preload" would be. What do you think?

@JirkaVebr
Copy link
Contributor

overoptimization

As in it would make the site too fast? What do you mean by that?

Hard maintainability is not worth it.

You're already inlining #{assetPath}/sprites/shapes.svg twice in two different files. Turning

script.
	initComponents = [
		{ name: 'ShapesIE', data: { url: '#{assetPath}/sprites/shapes.svg' } }
	]

into

- const shapesUrl = `${assetPath}/sprites/shapes.svg`
  
link(rel='preload', as='image', href=shapesUrl)
script.
	initComponents = [
		{ name: 'ShapesIE', data: { url: '#{shapesUrl}' } }
	]

does not really incur any maintainability overheads.

Now there may be perfectly legitimate reasons not to preload the sprite but I'd say the maintainability aspect you mention is not one of them.

@FilipChalupa
Copy link
Contributor Author

As in it would make the site too fast? What do you mean by that?

Nearly same speed for the cost of harder maintainability.

You're already inlining #{assetPath}/sprites/shapes.svg twice

I'm not happy about it. With IE dead there will be one occurrence only.

Meanwhile, two occurrences are less than three. Keep in mind that mango-cli-example is a very small project. Some can have more than one layout requiring the same rel='preload'/initComponents ... 'ShapesIE' in all of them.

Maintainability is not the main question. What will <link rel="preload" as="image" href="/assets/shapes.svg"> solve? From what I know browsers will discover rel="preload" almost at the same time as the first shape.

@enzy
Copy link
Contributor

enzy commented Jun 11, 2019

There were also other reasons (other than IE) not to use direct path but I can't remember it now.

A. It was the Microsoft Edge, which works now ✔️

B. And the more important problem I can see: ❌

SVG references this way has it's own separate DOM. It goes beyond the regular Shadow DOM boundary that all is subject to.... you can't style individual shapes like you could before.
https://css-tricks.com/svg-use-with-external-reference-take-2/#article-header-id-4

/* This won't work either way,
   because it crosses a shadow DOM boundary */
.icon-1 /* ~shadow~ */ .path-1 {
  fill: yellow;
}

Copy link
Contributor

@enzy enzy left a comment

Choose a reason for hiding this comment

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

Extract Failing build hotfix outside of this PR please and update it to the latest version (3.1.0 atm). Thank you.

@FilipChalupa
Copy link
Contributor Author

B. And the more important problem I can see: ❌

I didn't know that you can do this with shadow dom. Do we need to support this use case? Shapes are appropriate for simple icons anyway.

@FilipChalupa
Copy link
Contributor Author

FilipChalupa commented Jun 11, 2019

Extract Failing build hotfix outside of this PR please and update it to the latest version (3.1.0 atm). Thank you.

I'm ready to drop the commit after some fixes master. I don't have resources to migrate whole project. :(

@enzy
Copy link
Contributor

enzy commented Jun 11, 2019

Import and execute when the primary method fails.

Maybe an onload handler would be the way how to detect un/successful attempt. Give it some timeout and inject sprites if load hasn't happened yet.

From IE docs:

The onload event occurs when the browser has fully parsed the element and its descendants and is ready to act appropriately on that element, such as rendering the element to the target device. Before the event occurs, the browser must have loaded, parsed, and prepared referenced external resources for rendering. Optional external resources are not required to be ready for the event to occur.

@enzy
Copy link
Contributor

enzy commented Jun 11, 2019

I'm ready to drop the commit after some fixes master. I don't have resources to migrate whole project. :(

Okay, prepared #39 for this.


B. And the more important problem I can see: ❌

I didn't know that you can do this with shadow dom. Do we need to support this use case? Shapes are appropriate for simple icons anyway.

I can think of one example: animating of manGoweb logo would not be possible this way. But I agree that these special cases could use direct inline svg.

@FilipChalupa
Copy link
Contributor Author

Maybe an onload handler would be the way how to detect un/successful attempt. Give it some timeout and inject sprites if load hasn't happened yet.

  • It's too complicated to implement, test, maintain to support a deprecated browser.
  • How would timeout help? Why not listen to onerror? Besides, there is a risk of false positives/negatives.

@FilipChalupa
Copy link
Contributor Author

Okay, prepared #39 for this.

🔝 Thank you.

@FilipChalupa
Copy link
Contributor Author

I can think of one example: animating of manGoweb logo would not be possible this way. But I agree that these special cases could use direct inline svg.

So, are we ok with dropping the support of more complex cases since there are other ways to achieve the same like inlining or splitting a shape into two?

@FilipChalupa
Copy link
Contributor Author

Commit Failing build hotfix has been dropped. Cc. @enzy

Waiting for #39 to be merged.

@FilipChalupa FilipChalupa requested review from JirkaVebr and enzy and removed request for enzy June 12, 2019 11:56
use(xlink:href=`${assetPath}/sprites/shapes.svg#shape-${name}`)

//- IE fallback
use(xlink:href=`#shape-${name}`)
Copy link
Contributor

Choose a reason for hiding this comment

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

The polyfill code should handle this case (replace all occurences of en external resource to local one) and it should not be included in the HTML twice.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

  1. This way the code can be easily used in lazy loaded html content.
  2. IE is very bad at handling high JavaScript load. Scanning a whole page can do unnecessary harm during the page load while other work needs to be done too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@enzy What do you think? Is the double use justified?

@FilipChalupa
Copy link
Contributor Author

@JirkaVebr Is the <link rel="preload" as="image" href="/assets/shapes.svg"> still relevant?

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.

4 participants