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

[dom-if] is not as inert as <template> should be #1695

Closed
andrewebdev opened this issue May 31, 2015 · 4 comments
Closed

[dom-if] is not as inert as <template> should be #1695

andrewebdev opened this issue May 31, 2015 · 4 comments

Comments

@andrewebdev
Copy link

In 0.5, using a mix of media queries and I was able to create a component that would only load a specific based on said media queries. I've attempted to replicate this element in 1.0, unfortunately without success.

I have a Stack Overflow post here: http://stackoverflow.com/questions/30557315/polymer-1-0-dom-if-does-not-recalculate-when-previously-true

What I'm expecting is to see only one image displayed on the page based on the media query, with only one image requested over the network.

What I'm actually getting: All 4 images are requested at load time, and resizing the window does not get rid of a previously stamped template, which should now be hidden (so, 2 or more images ends up being visible on page, after resizing)

@clintonjrobinson
Copy link

@andrewebdev There is some non-documented (as of yet) feature in the dom-if template. https://github.com/Polymer/polymer/blob/master/src/lib/template/dom-if.html#L57

If you set restamp=true I think you may get the desired result?

<template is="dom-if" if="{{active}}" restamp="true"> <content></content> </template>

@arthurevans
Copy link

Not exactly undocumented. It's described here:

https://www.polymer-project.org/1.0/docs/devguide/templates.html#dom-if

And in the API reference under dom-if:

http://polymer.github.io/polymer/

@clintonjrobinson
Copy link

@arthurevans You are correct. It is documented, which makes sense since it is documented in the code and the docs seem to be autogenerated.

@andrewebdev
Copy link
Author

@clintonjrobinson thank you very much; I must've missed that somehow.

That said this still doesn't resolve the main reason I logged this issue. The content enclosed in the template tag is not entirely inert, as it was in 0.5.
You will notice in my example that I have 4 tags. Only one request should be made to the server for the current media query. But it's currently making all 4 requests on load.

selection_059

This approach to using the template to request only one of the images, worked fine in 0.5.

EDIT: Scrap that, I'm talking bollocks. Just reviewed my old implementation and is not that network friendly as I thought. I mistook it for a different implementation where I actually passed in the different src urls as attributes, not as img tags.

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

No branches or pull requests

3 participants