Publisher does not support the Fluid field type. Please do not contact asking when support will be available.

If you purchased an add-on from expressionengine.com, be sure to visit boldminded.com/claim to add the license to your account here on boldminded.com.

Ticket: Best practices for using Speedy with Publisher and the Publisher URL Prefix hidden for the default language

Status Resolved
Add-on / Version Speedy 1.1.1
Severity
EE Version 5.3.2

Stephen T

Jul 08, 2020

Hello!

I’m working on configuring Speedy static caching on a site that already has Publisher set up. This site has the “Add URL Prefix” Publisher setting turned on, as well as the setting to “Hide the prefix for the default language”.

I read in the Speedy static caching docs that the url_prefix parameter could be added to the {exp:speedy:static} tags like so:

{exp:speedy:static url_prefix="{publisher:current_language_code}”}

However, when I add in that parameter it doesn’t seem to work properly for the pages that are in the default language without the URL prefix in the URL. The page ends up cached with the /es/ version of the page and that’s what is displayed even if the URL loaded in the browser is just the default URL without “/es”. If I change the Publisher settings to turn off “Hide the prefix for the default language” then everything seems to work as expected.

Alternatively, if I remove the url_prefix parameter from the exp:speedy:static tag then the pages are cached properly for the default language, but aren’t cached for the Spanish pages that have /es in the URL.

Could you let me know what the best practice would be to use Speedy static page caching along with Publisher when the URL prefix is hidden for the default language?

Thanks for your help!

#1

BoldMinded (Brian)

Hi, Stephen! I’m not sure if I’ve actually tested that scenario, so it may be a day or two before I can replicate it and see why it might not be working. Have you tried using url_override=”{current_url}” instead of the url_prefix? Or url_override=”{publisher:current_language_code}/{current_url}”

#2

Stephen

Hi Brian!

I hadn’t tried the url_override parameter previously, but I just gave it a shot. I got some strange results using url_override=”{current_url}” or url_override=”{publisher:current_language_code}/{current_url}” because it was including https as the first URL segment.

I switched it out to url_override=”{current_path}” or url_override=”{publisher:current_language_code}/{current_path }”and either of those seemed to work for the default language URLs, but it didn’t cache the pages with /es in the URL (at least based on using the ?speedy_debug=1 query string and looking at the paths stored in the static folder).

Also I’m now noticing that with or without the url_override parameter, there are some pages where after I switch to Spanish on that page, it caches the Spanish output, but at the English URL. So switching back to English changes the URL, but keeps all the cached Spanish content visible.

Let me know if you’re able to test out that configuration and if it’s possible to set it up so it would cache both the English and Spanish pages properly without the URL prefix being used for the default language.

Thanks!

#3

BoldMinded (Brian)

Ok, this is kind of a long conditional, but it seems to work:

{exp:speedy:static {if publisher:current_language_code != publisher:default_language_code}url_prefix="{publisher:current_language_code}"{/if}}

I’m adding this variable to the next release, so if you want to add it manually you can use it now. In publisher/Service/Frontend.php line ~115 add this:

$this->config->_global_vars['publisher:is_default_language'] = $currentLanguage->getId() === $defaultLanguage->getId();

Then you can use a shorter conditional

{exp:speedy:static {if !publisher:is_default_language}url_prefix="{publisher:current_language_code}"{/if}}
#4

Stephen

Wonderful - I was just testing out some similar conditionals and the one you posted does seem to work. I added in that variable to the Frontend.php file as you suggested so I could use the shorter version of the conditional.

I did run into an issue where just the homepage wouldn’t cache when that conditional was used - neither the default language without the URL prefix or the /es version, but that issue seems to only be on one dev environment, so I’ll troubleshoot that issue separately. It is working properly in our other testing environments.

Thanks for your work on this!

#5

Stephen

Comment has been marked private.

#6

BoldMinded (Brian)

Thanks for catching that error on the docs page. Consider it fixed.

Login to reply