Some SEO or optimization apps change the execution order of my app block script, which prevents my app block from running normally.
These apps change the theme.liquid file and I have no way to stop it except manually code change. Previously, it’s the Avada SEO app. The latest one is Page Speed Optimizer.
Why does Shopify allow this? How can an app developer deal with this issue?
In my_app.js, I cannot get the handle variable. It’s undefined. I wait the js and CSS to be loaded with
window.addEventListener('DOMContentLoaded', function () {
console.log('handle = ', handle)
})
But the handle is undefined here. This is the liquid file added to the <head> of theme.liquid by the optimization app. It checks the script tags and disables them. I think this approach is destructive:
That code is from Speedien though I no longer see that particular in the app store. I think they are called Page Speed Optimizer LCP & CLS now. I’ve run into issues with them in the past.
I will add that I’ve had other SEO apps remove my code using JavaScript as well. Below is another example from Webrex where the app removes code (and this is the default behavior).
In the script above, they are removing all structured data from the theme and apps so that only their structured data remains.
After reporting it to Shopify on multiple occasions and never hearing back, I started telling the merchants about their bad behavior. It’s really shady to disable another app’s code, especially if the merchant isn’t aware of it.
Its frustrating though because merchants think our apps don’t work when really these other apps are preventing them from working and there is nothing we can do.
If you have theme access (WRITE), your app can check if the theme.liquid file contains the line of spdn and overwrites it with the unless code. This approach is automated
The manual change takes time for each user and I find the issue disappointing.
I don’t have write theme access nor do I want to get write access.
Manually changing the code becomes a game of who edited the theme code last, and it puts the merchant in a difficult situation because they don’t know what’s right or wrong.
I am not in the habit of editing other apps code much like I don’t want any other app to modify mine. However, I get that you do what you have to do.
I could also write a similar script that would block other apps code so that only mine shows, but that’s just crappy for the whole ecosystem and creates a war against other apps.
Ultimately, I wish Shopify would not allow apps to modify code using JavaScript like this.
I can confirm that this issue is escalating. Recently, a store approached us because their bundle functionality was malfunctioning. Upon investigation, we discovered two problematic behaviors from different apps:
One app had overridden the native window.fetch function, attempting to modify the request body but failing in the process
Another app added an event listener to buttons on the page during the capture phase, preventing the default action and stopping immediate propagation, effectively nullifying any other listeners attached to the same button
Such practices by apps severely degrade the merchant experience and should be prohibited.