3

If I visit a website with the facebook conversion pixel installed (such as https://www.walmart.com/), I notice that several different JavaScript files are loaded by the pixel.

The first one is https://connect.facebook.net/en_US/fbevents.js.

The second one is https://connect.facebook.net/signals/config/168539446845503?v=2.9.2&r=stable. This one seems to have some user specific configuration data baked into the file.

The third one is https://connect.facebook.net/signals/plugins/inferredEvents.js?v=2.9.2

What I don't understand is, why doesn't Facebook simply consolidate all of these into one request, like https://connect.facebook.net/en_US/168539446845503/fbevents.js?v=2.9.2&r=stable, and then simply return one file with everything in it? This would be able to do everything the conversion pixel does now, but with 1 request instead of 3.

user886596
  • 2,380
  • 5
  • 31
  • 53
  • Another problem I'm seeing with this is that `https://connect.facebook.net/signals/config/[CODE]?v=2.9.2&r=stable` file is just huge, in our case it's 150KB compressed, which is almost 0.5MB of js for browser to parse and execute which has negative performance impact on slower mobile devices. Any ideas how to make it smaller? – Pavel Gurecki Sep 23 '21 at 10:14

2 Answers2

4

As the page makes more than a hundred requests for its loading, loading 1 javascript file instead of 3 would not be a significant improvement.

Facebook chose to divide in 3 files for a better design, probably :

  • 1 generic library : fbevents.js
  • 1 more specific : inferredEvents.js, that uses the first one
  • 1 file that contains generated code, probably specific to the merchant 168539446845503 (Walmart?)

This fragmentation makes code maintenance easier (test, reusability, bug fix).

And finally, the generic files fbevents.js and inferredEvents.js can be cached by the browser and reused on other web sites. This is a kind of optimization, possibly better than the one you suggest.

user803422
  • 2,636
  • 2
  • 18
  • 36
  • Any idea what inferredEvents.js does specifically? – fabb Sep 24 '19 at 14:30
  • BTW since Chrome 85 (after you wrote this answer) there is a feature Cache Partitioning (https://developer.chrome.com/blog/http-cache-partitioning/) which means even for `sdk.js` (with no query parameters) gets downloaded for every site so there is no longer any caching across sites. – Simon_Weaver Apr 13 '22 at 18:16
0

Having multiple resource requests to the same origin is FAR FAR less of an issue than it was a few years ago:

  1. Internet speeds and are much faster.
  2. Latency is less (most notably so on 5G phones).
  3. HTTP/3 protocol has many improvements which help when multiplexing files simultaneously from the same server.
  4. Browsers don't limit active number of connections to a site as agressively they used to (that doesn't matter with HTTP/3 anyway).

Facebook uses HTTP/3 as you can see here:

enter image description here

Simon_Weaver
  • 140,023
  • 84
  • 646
  • 689