Accurately background-loading the MktoForms2 global object | Community
Skip to main content
SanfordWhiteman
New Participant
February 17, 2021

Accurately background-loading the MktoForms2 global object

  • February 17, 2021
  • 13 replies
  • 12532 views
Content backfill required
This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

13 replies

New Participant
March 6, 2021

Just as I mentioned in the other thread, page speed score doesn't really work like that. When you put it into a professional marketing site that is already going to struggle for a 90+ score depending on its UX, the weight of the Marketo library is game changing.

Sure, it would be great if we could ignore automated tests, but that's not the age we're in. Try explaining that fear to an SEO team or really even a CRM team that understands the SEO impact of performance scores when you're dealing with top brands, and you'll have a better understanding of that "fear" and a more rational reasoning for balance. Getting people to your Marketo forms is debatably more important than how fast they load.

SanfordWhiteman
New Participant
February 25, 2021

Don't see what you're describing with Lighthouse at all.

 

As seen here, a page using the method above scores 100/100 for performance. (Same 100/100 on Desktop and Mobile.)

 

 

We wouldn't be prescribing a purposeful delay in the human usability of the page out of fear of an automated test result.

 

New Participant
February 25, 2021

A great way to do it! I will say though that the `defer` attribute is not quite enough if you've set your sites on performance. Anything under 3 seconds of attempting to load the Marketo library will cause Lighthouse to include it in its performance report. Something you can add to make sure you get those three seconds:

 

<script type="text/javascript">setTimeout(function(){var mscript = document.createElement("script");mscript.src="//forms.mysite.com/js/forms2/js/forms2.min.js";var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(mscript, s);},3000);</script>

 

The code above  replaces:

 

<script src="https://pages.example.com/js/forms2/js/forms2.min.js" defer></script>

 

The sample above will get you where you need to be, but I'd recommend having all of your script blocks just before the closing `</body>` tag.

You will however be facing concerns from your CRM team in regards to potential drop off before the form loads though.

Is Marketo planning on releasing a new version of the JS API that doesn't have jQuery and is better performance optimized for modern speed tests?