Skip to content

Commit

Permalink
Speed up instagram and twitter embeds.
Browse files Browse the repository at this point in the history
1. Avoid redirect for instagram iframe (by going directly to www).
2. Preconnect to Twitter image host.
3. Preconnect to Instagram image host.
  • Loading branch information
cramforce committed Feb 19, 2016
1 parent 1f61fdb commit 26ed564
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
4 changes: 2 additions & 2 deletions extensions/amp-instagram/0.1/amp-instagram.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ import {loadPromise} from '../../../src/event-helper';
class AmpInstagram extends AMP.BaseElement {
/** @override */
preconnectCallback(onLayout) {
this.preconnect.url('https://instagram.com', onLayout);
this.preconnect.url('https://www.instagram.com', onLayout);
}

/** @override */
Expand All @@ -63,7 +63,7 @@ class AmpInstagram extends AMP.BaseElement {
const iframe = document.createElement('iframe');
iframe.setAttribute('frameborder', '0');
iframe.setAttribute('allowtransparency', 'true');
iframe.src = 'https://instagram.com/p/' +
iframe.src = 'https://www.instagram.com/p/' +
encodeURIComponent(shortcode) + '/embed/?v=4';
this.applyFillContent(iframe);
iframe.width = width;
Expand Down
2 changes: 1 addition & 1 deletion extensions/amp-instagram/0.1/test/test-amp-instagram.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ describe('amp-instagram', () => {
const iframe = ins.firstChild;
expect(iframe).to.not.be.null;
expect(iframe.tagName).to.equal('IFRAME');
expect(iframe.src).to.equal('https://instagram.com/p/fBwFP/embed/?v=4');
expect(iframe.src).to.equal('https://www.instagram.com/p/fBwFP/embed/?v=4');
expect(iframe.getAttribute('width')).to.equal('111');
expect(iframe.getAttribute('height')).to.equal('222');
});
Expand Down
2 changes: 2 additions & 0 deletions extensions/amp-twitter/0.1/amp-twitter.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ class AmpTwitter extends AMP.BaseElement {
preconnectCallback(onLayout) {
// This domain serves the actual tweets as JSONP.
this.preconnect.url('https://syndication.twitter.com', onLayout);
// All images
this.preconnect.url('https://pbs.twimg.com', onLayout);
// Hosts the script that renders tweets.
this.preconnect.prefetch('https://platform.twitter.com/widgets.js');
prefetchBootstrap(this.getWin());
Expand Down

0 comments on commit 26ed564

Please sign in to comment.