Avoid duplicate loading of Forms2.js?

Anonymous
Not applicable

Avoid duplicate loading of Forms2.js?

Hi,

We are only calling forms2.js and munchkin.js once in our base code, but on page inspection on dev tools under network, there seems to be two insertions of forms2.js and two insertions of munchkin.js.

There's the version that we included (forms2.js?ver=4.2.5), and a minified version (forms2.min.js) called in an XDframe. Why does Marketo not serve the minified version to begin with?

Any way to avoid duplicate loading of scripts?

Thanks

6 REPLIES 6
Anonymous
Not applicable

Re: Avoid duplicate loading of Forms2.js?

Having the same issue here.

Including "https://app-sj01.marketo.com/js/forms2/js/forms2.min.js" once but "forms2.min.js" is being requested twice on the page load.

After a quick I investigation, i found that the first request for "forms2.min.js" is being made from the page which is the intention but the second request is being made by a Marketo source which is "https://app-sj01.marketo.com/index.php/form/XDFrame".

How can I prevent this duplicate forms2.min.js requests?

Any solution to this? Anyone?

SanfordWhiteman
Level 10 - Community Moderator

Re: Avoid duplicate loading of Forms2.js?

You cannot.  The script cannot be shared between the main document and the xdframe due to age-old browser restrictions.  It needs to be loaded in each context. 

Steve_Carlton
Level 2

Re: Avoid duplicate loading of Forms2.js?

Dealing with this issue today as we are trying to get two forms loading on the same page and loading forms2.min.js multiple times is causing each form to show up multiple times.

Since we cannot share the script across multiple elements does this essentially mean there is a hard limit of one form per page?

SanfordWhiteman
Level 10 - Community Moderator

Re: Avoid duplicate loading of Forms2.js?

The inner load of forms2.min.js in the cross-domain frame is not causing this problem. It can't be, because the main document only sees the main document's scope.

And you don't have to load forms2.js twice in the main document to have 2 forms.

If you post a sample URL I can tell you what's really happening, but I doubt it's what you think.

Steve_Carlton
Level 2

Re: Avoid duplicate loading of Forms2.js?

Thanks Sanford, since you ruled that out for me I took another look and as you stated the issue was unrelated.

Our website is in development an still has a lot of placeholder forms/sections. I believe the issue was related to the two placeholder forms being the same form ID. Once I replaced one form with a different ID the issue seemed to resolve itself.

SanfordWhiteman
Level 10 - Community Moderator

Re: Avoid duplicate loading of Forms2.js?

Yep, that's consistent with expectations. Marketo locates the form by whether the <FORM> element exists, regardless of whether it contains child elements (which is actually convenient in some cases).

Now, there are some interesting bugs with multiple forms on the same page that you may need to manage, like this one: http://blog.teknkl.com/marketo-forms-2-0-datepicker-polyfill-bug-w-multiple-forms/  But at core, multiple forms are fine.