Is the new crossorigin attribute speeding up AdSense ads?

In July 2021, Google AdSense announced a change in its ad code that comes with a performance enhancement. It sounds like it might be related to Google’s Web Vitals scores, which will be a ranking factor for their search engine.

Summary

  • AdSense added two new attributes to their ad codes: crossorigin and client.
  • There is no deadline to change the existing codes on your website.
  • We haven’t found a performance benefit.
  • If you manage your Auto ads code and AdSense ads with Advanced Ads, then our update will adjust all your codes automatically

What did AdSense change?

The first line of ad unit codes now includes the client parameter with your publisher ID and the crossorigin attribute.

The client parameter was already added to the auto ads code in a previous AdSense code update.

As a result, the first line of individual ad units is identical to the general auto ads code.

It looks like this:

<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-1234"
     crossorigin="anonymous"></script>Code language: HTML, XML (xml)

What does crossorigin mean?

crossorigin is an attribute that not only AdSense uses. You can find explanations on mozilla.org or w3schools.com. It tells the browser whether it can share user information with another domain.

The “anonymous” keyword means that there will be no exchange of user credentials via cookies, client-side SSL certificates or HTTP authentication […], unless it is in the same origin.

https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/crossorigin

Or in other words, AdSense should not be able to read cookie information stored on your website.

How is this related to a performance enhancement of AdSense ads? It is possible that because the file is downloaded in anonymous mode by the crossorigin attribute, there is no authentication, and no cookies are downloaded. Maybe handling user information impacts the performance. With Google working towards banning third-party cookies, this is no longer needed anyway.

I reached out to AdSense for more information and will update this post when I receive them.

After some discussion with our team, I believe that the client attribute might allow some performance benefits. AdSense could use that information to customize the request to their server based on the user account, without first having to read the website where the code is embedded on.

How fast is the new Google AdSense code?

Any ad codes that load content from external sites, including AdSense, impact the perceived and measured website performance. That’s the tradeoff for making a living from ads.

So, of course, I was curious to learn how much AdSense could speed up its ads.

Google is not very specific about what publishers can expect from the code change.

The new AdSense code allows AdSense to trigger optimization features earlier which can improve the performance of the ads on your site.

https://support.google.com/adsense/answer/10627874

Let’s measure the actual impact.

I set up a new WordPress site with just Advanced Ads to automatically inject an AdSense ad at the top of each post. I choose the Plain Text ad type and just copied the AdSense code from my account into it. The codes they give you already include the crossorigin="anonymous" attribute and the client parameter.

AdSense code with the crossorigin attribute
AdSense single ad code with crossorigin attribute

I created another ad with the same ad code, but I removed crossorigin and client this time.

Now I choose one version, went to PageSpeed Insights, and let it measure the speed. Then I changed the ad and repeated the process.

Result of a PageSpeed Insights test with the score 51 out of 100.
Sample score of my AdSense page speed test

I did this three times for each version. These are the page speed scores they gave me.

  • score with the new code: 49, 56, 56
  • score with the old code: 59, 51, 58

While this is not a scientific test, the result is far from indicating a positive effect on the page speed.

How to update your AdSense codes

New ad units and the auto ads code now start with a line like this:

<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-1234"
   crossorigin="anonymous"></script>Code language: HTML, XML (xml)

The client parameter contains your personal AdSense publisher ID.

Get code from your AdSense account

The codes you get from your AdSense account are correct. Just find the Auto ads code or individual ad codes there.

In their article, AdSense recommends updating all codes at once. It is simpler when using Advanced Ads. See the next section.

Use Advanced Ads to manage AdSense ads

If you manage your AdSense ad units with Advanced Ads, then there is probably nothing to do.

Even though there is no measurable performance benefit, we decided to go with their recommendation and update the AdSense ad codes managed by Advanced Ads. Please note that this only applies to the Auto ads option on Advanced Ads > Settings > AdSense and the AdSense ad type.

So unless you insert your AdSense ads with the Plain text and Code ad type, you don’t need to do anything else. But if you use this ad type for AdSense, you would need to add the crossorigin attribute and client parameter manually to the ad code.

Our performance tests have shown that the new code could actually perform worse than the old ones. We trace that back to the client parameter being added to the script.

This is why we allow developers to opt out of the automatic code update within Advanced Ads. Add the following line to your theme’s functions.php or a custom plugin.

add_filter( 'advanced-ads-adsense-publisher-id', '__return_false' );Code language: JavaScript (javascript)

What about crossorigin and AMP?

I know some of you will ask, so let me answer right away: The new attribute is neither needed nor supported on the AMP version of your ads. Advanced Ads also takes care of that.

Resources

Make it better

Increase your ad management skills without spending more time.
Join over 150,000 publishers and AdOpts increasing their ad revenue.