Cache issues: Erratic lang switcher in frontend and unable to "logout As" in backend

Describe the issue or problem
At certain pages and in a kind of random way, the lang switcher of my theme is not working.
When I disable the local cache, the lang switcher works as expected.

Steps I took leading up to the issue
For example:

  1. Go to https://revistes.uab.cat/jhsgl/about
  2. Select a different language with the top-right “language” dropdown.
  3. Notice lang won’t change.
  4. Enable the Inspector (chromium or firefox) and check on “Disable cache”
  5. Switch the lang again and notice it works fine.

What application are you using?

  • OJS 3.2.1-4
  • OJS 3.3.0-13

Additional information
The theme lang switcher uses same url than the original lang switcher:
https://revistes.uab.cat/jhsgl/user/setLocale/es_ES?source=%2Fjhsgl%2Fabout

Any idea how the local caching could be messing things?

Hi @marc

I’ve run some tests against this journal. I could reproduce the issue, but when I navigate to a different page on the journal, it shows the last language I’ve attempted to switch.
I got make the lang switcher changing when I access each language directly:
https://revistes.uab.cat/jhsgl/user/setLocale/es_ES
https://revistes.uab.cat/jhsgl/user/setLocale/es_CA
https://revistes.uab.cat/jhsgl/user/setLocale/en_US

Given it seems that you are using a child theme from Default Theme, could you please test on a local installation whether enabling the Default Theme also results on the same issue?

Best,
Israel

1 Like

Hi @israel.cefrin

Sorry for my silence. Multiple fronts and only two hands. :wink:

I couldn’t reproduce the issue with the default theme (this is quite random)… but I found a related extra issue with the backend… when I try to “logout As” after an impersonation (ojs don’t logout and keep you with the secondary user).

As far as the problem disappears in the moment I disable browser’s cache I recalled when I made last changes related with this… and (I think) it emerged when I started to optimize apache performance applying the following rules:

        # Enable Compression
        <IfModule mod_deflate.c>
          AddOutputFilterByType DEFLATE text/text text/html text/plain text/xml text/css application/x-javascript application/javascript
          BrowserMatch ^Mozilla/4 gzip-only-text/html
          BrowserMatch ^Mozilla/4\.0[678] no-gzip
          BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
        </IfModule>

        # Expires Headers - 2678400s = 31 days
        <IfModule mod_expires.c>
          ExpiresActive On
          ExpiresDefault "access plus 1 seconds"
          ExpiresByType text/html "access plus 7200 seconds"
          ExpiresByType image/gif "access plus 2678400 seconds"
          ExpiresByType image/jpeg "access plus 2678400 seconds"
          ExpiresByType image/png "access plus 2678400 seconds"
          ExpiresByType text/css "access plus 518400 seconds"
          ExpiresByType text/javascript "access plus 2678400 seconds"
          ExpiresByType application/x-javascript "access plus 2678400 seconds"
        </IfModule>

        # Cache Headers
        <IfModule mod_headers.c>
          # Cache specified files for 31 days
          <FilesMatch "\.(ico|flv|jpg|jpeg|png|gif|css|swf)$">
            Header set Cache-Control "max-age=2678400, public"
          </FilesMatch>
          # Cache HTML files for a couple hours
          <FilesMatch "\.(html|htm)$">
            Header set Cache-Control "max-age=7200, private, must-revalidate"
          </FilesMatch>
          # Cache PDFs for a day
          <FilesMatch "\.(pdf)$">
            Header set Cache-Control "max-age=86400, public"
          </FilesMatch>
          # Cache Javascripts for 31 days
          <FilesMatch "\.(js)$">
            Header set Cache-Control "max-age=2678400, private"
          </FilesMatch>
        </IfModule>

As you will notice, JS has expiration marks, is cached and compressed… so I tried removing the expiration and caching and problem persisted.

Then I tried to clean all the existing caches (note here for future references, so please correct me if I missed something) that, from server side to client, are:

  1. OJS cache (cleaning with “find /var/www/html/cache -type f -delete”)
  2. OJS memcache (disabled by default in config.inc.php)
  3. Apache opcache (enabled > disabled in htaccess with “php_flag opcache.enable Off”)
  4. Reverse proxy (traefik has no caching by default)
  5. Browser local caching (with FF, Chromium)

And problem persists… so I will try to disable compression and (if it still fails) then all the rules, so at least we will know the culprit.

Thanks for your help Israel.

Take care,
m.

Update:

I disabled the optimization rules (as well as the apache “expires_module”) and things are back to normal.

So, I’m wondering what collides in OJS with those optimizations (that BTW, are make the site faster).

I love to help debugging, but my frontend skills are very rusted/outdated.
If I can do something to identify the issue, please let me know.

For instance, if you think it’s helpful, I will setup an OJS (3.3.0-14 and/or 3.4) clean installation with the former rules to see if we can reproduce the issue.

Cheers,
m.