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
amp-instagram placeholder should not prerender #4700
amp-instagram placeholder should not prerender #4700
Conversation
5d65184
to
9fbb633
Compare
const image = this.win.document.createElement('amp-img'); | ||
// This will redirect to the image URL. By experimentation this is | ||
// always the same URL that is actually used inside of the embed. | ||
image.setAttribute('src', 'https://www.instagram.com/p/' + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would just calling sanitizer.resolveUrlAttr
against this URL allow us to serve it from the CDN instead? cc/ @dvoytenko
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also it looks like using api.instagram.com
instead of www.instagram.com
works similarly though the documentation only mentions the naked domain.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
awesome, this seems fixed and we go through the cache.
33d6fdb
to
1e08477
Compare
disregard original statements since it looks like the instagram imaged is proxied |
LGTM |
e77c92d
to
1aa0d71
Compare
@@ -85,8 +86,10 @@ class AmpInstagram extends AMP.BaseElement { | |||
const image = this.win.document.createElement('amp-img'); | |||
// This will redirect to the image URL. By experimentation this is | |||
// always the same URL that is actually used inside of the embed. | |||
image.setAttribute('src', 'https://www.instagram.com/p/' + | |||
encodeURIComponent(this.shortcode_) + '/media/?size=l'); | |||
const imgSrc = resolveUrlAttr('amp-img', 'src', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In my opinion, we shouldn't proxy an Instagram image. We should either find a way to get it from their cookieless CDN or exclude it from prerendering. The reasons are:
- They will most likely immediately throttle any AMP CDN
- This prefetch will miss the cache when the actual widget is downloaded, which makes pre-fetch a lot less useful.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so i think last time i mentioned the only way I know of how to get the cdn url is to hit an endpoint:
http://api.instagram.com/oembed?callback=&url=https%3A%2F%2Finstagram.com%2Fp%2FfBwFP
Would that be viable?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
response looks like:
{
"provider_url": "https://www.instagram.com",
"media_id": "520552783_242517",
"author_name": "cramforce",
"height": null,
"thumbnail_url": "https://instagram.fsnc1-1.fna.fbcdn.net/t51.2885-15/e15/924722_1467037386920481_2122071451_n.jpg?ig_cache_key=NTIwNTUyNzgz.2",
"thumbnail_width": 612,
"thumbnail_height": 612,
"provider_name": "Instagram",
"title": "",
"html": "<blockquote class=\"instagram-media\" data-instgrm-version=\"7\" style=\" background:#FFF; border:0; border-radius:3px; box-shadow:0 0 1px 0 rgba(0,0,0,0.5),0 1px 10px 0 rgba(0,0,0,0.15); margin: 1px; max-width:658px; padding:0; width:99.375%; width:-webkit-calc(100% - 2px); width:calc(100% - 2px);\"><div style=\"padding:8px;\"> <div style=\" background:#F8F8F8; line-height:0; margin-top:40px; padding:50% 0; text-align:center; width:100%;\"> <div style=\" background:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACwAAAAsCAMAAAApWqozAAAABGdBTUEAALGPC/xhBQAAAAFzUkdCAK7OHOkAAAAMUExURczMzPf399fX1+bm5mzY9AMAAADiSURBVDjLvZXbEsMgCES5/P8/t9FuRVCRmU73JWlzosgSIIZURCjo/ad+EQJJB4Hv8BFt+IDpQoCx1wjOSBFhh2XssxEIYn3ulI/6MNReE07UIWJEv8UEOWDS88LY97kqyTliJKKtuYBbruAyVh5wOHiXmpi5we58Ek028czwyuQdLKPG1Bkb4NnM+VeAnfHqn1k4+GPT6uGQcvu2h2OVuIf/gWUFyy8OWEpdyZSa3aVCqpVoVvzZZ2VTnn2wU8qzVjDDetO90GSy9mVLqtgYSy231MxrY6I2gGqjrTY0L8fxCxfCBbhWrsYYAAAAAElFTkSuQmCC); display:block; height:44px; margin:0 auto -44px; position:relative; top:-22px; width:44px;\"></div></div><p style=\" color:#c9c8cd; font-family:Arial,sans-serif; font-size:14px; line-height:17px; margin-bottom:0; margin-top:8px; overflow:hidden; padding:8px 0 7px; text-align:center; text-overflow:ellipsis; white-space:nowrap;\"><a href=\"https://www.instagram.com/p/fBwFP/\" style=\" color:#c9c8cd; font-family:Arial,sans-serif; font-size:14px; font-style:normal; font-weight:normal; line-height:17px; text-decoration:none;\" target=\"_blank\">A photo posted by Malte Ubl (@cramforce)</a> on <time style=\" font-family:Arial,sans-serif; font-size:14px; line-height:17px;\" datetime=\"2012-01-07T03:37:39+00:00\">Jan 6, 2012 at 7:37pm PST</time></p></div></blockquote>\n<script async defer src=\"//platform.instagram.com/en_US/embeds.js\"></script>",
"width": 658,
"version": "1.0",
"author_url": "https://www.instagram.com/cramforce",
"author_id": 242517,
"type": "rich"
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I could see this possible but:
- Not sure additional latency justifies it.
- Can we actually make requests to this API from AMP? Does it need some sort of a key?
- Is this API itself cookie-less? We can, of course, send a uncredentialed CORS request to ensure that it is, but I'm not sure what requirements are there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There would actually be no extra latency. The current request pattern is
- Request to instagram
- Redirect to CDN.
I don't think it'll work, though. The API @erwinmombay mentioned is designed for JSONP (no CORS support), then their real API (not the oembed endpoint) requires an access token.
I think for now we can just guard the existing code behind whenFirstVisible
promise. Having an instagram in the first viewport is quite uncommon anyway, which makes this essentially a null change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ideally we should do it via property. These calls are made often and reading an attribute is pretty slow.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SGTM
On Tue, Aug 30, 2016 at 5:22 PM, Dima Voytenko notifications@github.com
wrote:
In extensions/amp-instagram/0.1/amp-instagram.js
#4700 (comment):@@ -85,8 +86,10 @@ class AmpInstagram extends AMP.BaseElement {
const image = this.win.document.createElement('amp-img');
// This will redirect to the image URL. By experimentation this is
// always the same URL that is actually used inside of the embed.
- image.setAttribute('src', 'https://www.instagram.com/p/' +
encodeURIComponent(this.shortcode_) + '/media/?size=l');
- const imgSrc = resolveUrlAttr('amp-img', 'src',
Ideally we should do it via property. These calls are made often and
reading an attribute is pretty slow.—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/ampproject/amphtml/pull/4700/files/1aa0d710d3dccdfc767a4c932c5020abf0660c6e#r76904683,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAFeT7p6vZ5D9vuqPnsNYHIBllEE-hFFks5qlMkygaJpZM4JskC5
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should be internal only anyway.
On Tue, Aug 30, 2016 at 5:51 PM, Malte Ubl malte.ubl@gmail.com wrote:
SGTM
On Tue, Aug 30, 2016 at 5:22 PM, Dima Voytenko notifications@github.com
wrote:In extensions/amp-instagram/0.1/amp-instagram.js
#4700 (comment):@@ -85,8 +86,10 @@ class AmpInstagram extends AMP.BaseElement {
const image = this.win.document.createElement('amp-img');
// This will redirect to the image URL. By experimentation this is
// always the same URL that is actually used inside of the embed.
- image.setAttribute('src', 'https://www.instagram.com/p/' +
encodeURIComponent(this.shortcode_) + '/media/?size=l');
- const imgSrc = resolveUrlAttr('amp-img', 'src',
Ideally we should do it via property. These calls are made often and
reading an attribute is pretty slow.—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/ampproject/amphtml/pull/4700/files/1aa0d710d3dccdfc767a4c932c5020abf0660c6e#r76904683,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAFeT7p6vZ5D9vuqPnsNYHIBllEE-hFFks5qlMkygaJpZM4JskC5
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dvoytenko does this need to be done in base-element?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you answers offline, this should just be done for amp-img for now
Un-LGTM to address @dvoytenko comments.
These are good points, I guess the quick solution is for now to drop the placeholder as you had before @erwinmombay until we can maybe get in touch with someone from Instagram and see if they have a better way to get the media. |
620ee14
to
39adf0a
Compare
@dvoytenko @mkhatib PTAL |
also had to fix some viewer.html code so i could test prerender correctly |
LGTM |
@@ -40,6 +40,12 @@ export class AmpImg extends BaseElement { | |||
} | |||
|
|||
/** @override */ | |||
buildCallback() { | |||
/** @private @const {boolean} */ | |||
this.isPrerenderAllowed_ = !this.element.hasAttribute('no-prerender'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's call it noprerender
since it's our most typical "no" form.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
LGTM with one request |
39adf0a
to
ee6bf26
Compare
* remove amp-instagram default placeholder * remove amp-instagram default placeholder * no-prerender -> noprerender
* remove amp-instagram default placeholder * remove amp-instagram default placeholder * no-prerender -> noprerender
this is temporary until we can hit the image url on the cdn directly without having to go through the www.instagram.com link (which redirects to the cdn url)
at minimum i wish we could use a generic instagram placeholder image like their gray logo or one of their assets (like in https://www.instagram-brand.com/)
cc @rudygalfi @adewale