1

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:

<script type="text/javascript">
/*<![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 < 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();
})();
/*]]>*/
</script>

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?

  • 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. – billythekid May 14 at 14:38
  • 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 May 15 at 20:06
  • 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? – Nicolas Bouliane May 17 at 9:04
  • 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. – Nicolas Bouliane May 17 at 10:04
  • @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 May 17 at 19:47
1

You can set the 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.

| improve this answer | |
  • 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. – Nicolas Bouliane May 17 at 20:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.