vendredi 28 septembre 2018

EmberJS: do web crawlers wait while I set my canonical link asynchronously?

I am working on an EmberJS application, and I want add a canonical link to the <head> tags,

<link rel="canonical" href="https://www.my-domain.com"/>

When the didTransition method of the Ember.Router runs, surprisingly - at least for me - the window.location.pathname is still that of the departure page, not that of the arrival page. Therefore, the only way I found to populate the canonical link is by using Ember.run.next, which - if I understand correctly - is just a wrapper of setTimeout(, 0).

didTransition: function () {
  this._super(...arguments);

  run.next(() => {
    $('link[rel=canonical]').attr('href', 'https://www.my-domain.com' + window.location.pathname);
  });

  return true;
},

As my main purpose is SEO, I was wondering how web crawlers treat 0-delay setTimeout, and whether or not I am defeating the whole purpose of my task by using setTimeout. Can anyone help?




Aucun commentaire:

Enregistrer un commentaire