<p>You can set the <a href="https://docs.craftcms.com/v3/config/config-settings.html#runqueueautomatically" rel="nofollow noreferrer">runQueueAutomatically</a> config setting to <code>false</code> to prevent this.</p>

<p>You'll just want to set up an alternative way to process the queue as noted in the docs.</p>

CC BY-SA 4.0
2020-05-17T20:28:22.197Z
This is what I did. I set up a cron job to replace the current queue runner using the line in the docs you have linked. It's working flawlessly.
nicbou
CC BY-SA 4.0
2020-05-14T23:57:36.133Z
2020-05-14T23:57:36.133Z
Brad Bell
<p>I have a website that resides behind a static cache. Today, I realised that some of the cached pages contain this bit of JavaScript at the end:</p>

<pre><code>&lt;script type="text/javascript"&gt;
/*&lt;![CDATA[*/
(function(){
    var XMLHttpFactories = [
        function () {return new XMLHttpRequest()},
        function () {return new ActiveXObject("Msxml2.XMLHTTP")},
        function () {return new ActiveXObject("Msxml3.XMLHTTP")},
        function () {return new ActiveXObject("Microsoft.XMLHTTP")}
    ];
    var req = false;
    for (var i = 0; i &lt; XMLHttpFactories.length; i++) {
        try {
            req = XMLHttpFactories[i]();
        }
        catch (e) {
            continue;
        }
        break;
    }
    if (!req) return;
    req.open('GET', "https://allaboutberlin.com/index.php/actions/queue/run", true);
    if (req.readyState == 4) return;
    req.send();
})();
/*]]&gt;*/
&lt;/script&gt;
</code></pre>

<p>Since the page is cached, every page loads makes this HTTP request, and it could easily bring my website down if it gets a traffic spike. How do I disable this feature?</p>

CC BY-SA 4.0
2020-05-14T14:38:41.587Z
This appears to be added by the queue/Queue.php `handleResponse()` method. I wonder if it'll be turned off by setting `runQueueAutomatically` to false?
Edit: I just turned that setting off on a local environment for a site I'm currently developing and it removed the script from the page. Incidentally, you'd think it would be better added by registerJs rather than banging it in after the closing html tag and invalidating your page.
billythekid
CC BY-SA 4.0
2020-05-15T20:06:21.457Z
Looks like you're using nginx caching? Make sure it's set properly or you'll be caching your own visits while logged in to the admin which can be very problematic...
RitterKnight
CC BY-SA 4.0
2020-05-17T09:04:46.763Z
Thanks. I think @RitterKnight has the right idea. I'll figure out a way to disable the cache if the user is logged in. Do you know which hints I could use to spot a logged in user from nginx? Perhaps a session token?
nicbou
CC BY-SA 4.0
2020-05-17T10:04:28.877Z
It appears that this is still a problem when logged out. If I clear the fastcgi cache, and load the website in incognito mode, the script is still appended to the page.
nicbou
CC BY-SA 4.0
2020-05-17T19:47:07.573Z
@NicolasBouliane: Is your site still the Berlin one in the question? Not sure if you tried turning off the cache or turned it back on but I still see ``x-cache: HIT`` in the header. I also don't see the script in question from any of the pages I visited...
RitterKnight
CC BY-SA 4.0
2020-05-17T20:27:58.650Z
Yes, I deployed the fix earlier today. I disabled runQueueAutomatically and used cron instead. The script appeared even if I was logged out.
nicbou
<cache><queue>
How to prevent Craft from injecting scripts in the page?
# How to prevent Craft from injecting scripts in the page?

(Asked by: username_0 on 2020-05-14)

I have a website that resides behind a static cache. Today, I realised that some of the cached pages contain this bit of JavaScript at the end:


Since the page is cached, every page loads makes this HTTP request, and it could easily bring my website down if it gets a traffic spike. How do I disable this feature?

**Tags:** cache, queue
> **Comments:**
> **username_1**: This appears to be added by the queue/Queue.php `handleResponse()` method. I wonder if it'll be turned off by setting `runQueueAutomatically` to false? Edit: I just turned that setting off on a local environment for a site I'm currently developing and it removed the script from the page. Incidentally, you'd think it would be better added by registerJs rather than banging it in after the closing html tag and invalidating your page.  
> **username_2**: Looks like you're using nginx caching? Make sure it's set properly or you'll be caching your own visits while logged in to the admin which can be very problematic...  
> **username_0**: Thanks. I think @RitterKnight has the right idea. I'll figure out a way to disable the cache if the user is logged in. Do you know which hints I could use to spot a logged in user from nginx? Perhaps a session token?  
> **username_0**: It appears that this is still a problem when logged out. If I clear the fastcgi cache, and load the website in incognito mode, the script is still appended to the page.  
> **username_2**: @NicolasBouliane: Is your site still the Berlin one in the question? Not sure if you tried turning off the cache or turned it back on but I still see ``x-cache: HIT`` in the header. I also don't see the script in question from any of the pages I visited...  
> **username_0**: Yes, I deployed the fix earlier today. I disabled runQueueAutomatically and used cron instead. The script appeared even if I was logged out.  

---

## 1 answers

### Answer by username_3 on 2020-05-14. Score: 2

You can set the [runQueueAutomatically](https://docs.craftcms.com/v3/config/config-settings.html#runqueueautomatically) config setting to `false` to prevent this.

You'll just want to set up an alternative way to process the queue as noted in the docs.

> **Comments:**
> **username_0**: This is what I did. I set up a cron job to replace the current queue runner using the line in the docs you have linked. It's working flawlessly.  

---

