Multilagual multihost assets permalink

Hello,

what is the best way to make assets permalink be generated correctly for multilangual multihost site?

I want to build a website which has multiple host names for each translation

Config file:

[languages]
  [languages.en]
    baseURL = "https://www.example.com"
    weight = 1
  [languages.cs]
    baseURL = "https://www.example.cz"
    weight = 2

And asset referenced in a template:

{{ $indexJS := resources.Get "js/index.js" | resources.Fingerprint "sha256" }}
<script type="text/javascript" src="{{ $indexJS.Permalink }}" integrity="{{ $indexJS.Data.Integrity }}"></script>

But this setting is always (for both translations) building a permalink with baseURL of the language with lowest weight. For local server there is localhost and port of the language too:

<script type="text/javascript" src="http://localhost:1313/js/index.532cd6d4dd8914b1545e914c99d3816fc806a7a24058f8c01f8576544aec2bc9.js" integrity="sha256-UyzW1N2JFLFUXpFMmdOBb8gGp6JAWPjAH4V2VErsK8k="></script>

while localhost:1314 is expected for the cs version of the site.

I can make it work correctly by using .RelPermalink and absLangUrl

{{ $indexJS := resources.Get "js/index.js" | resources.Fingerprint "sha256" }}
<script type="text/javascript" src="{{ $indexJS.RelPermalink | absLangURL }}" integrity="{{ $indexJS.Data.Integrity }}"></script>

But I would expect the .Permalink to work directly. Is this an expected behavior? If so, can I somewhere read more about the reasons for the actual implementation?

Thank you!

Could it be that you are caching the partial that creates the script link? That was an error I had a while ago.

{{ $indexJS := resources.Get "js/index.js" | resources.Fingerprint "sha256" }}
<script type="text/javascript" src="{{ $indexJS.RelPermalink | absLangURL }}" integrity="{{ $indexJS.Data.Integrity }}"></script>

If the location where you include this partial does partialCached then it’s only created one time. Read up on partialCached - there are ways to create one cached partial per language.

I never tried, but I think {{ partialCached "filename.html" . $language }} should do the trick - if you set $language :wink:

Unfortunately I’m not using a cached partial. Partial is inserted like this {{ partial "footer.html" . }}. I have tried the {{ partialCached "filename.html" . $language }} variant but it seems it didn’t help and .Permalink is still referencing the first language.

(If I read the docs correctly, partialCached should respect language out of the box.)

**Note:**  Each Site (or language) has its own  `partialCached`  cache, so each site will execute a partial once.

Anyways thanks for your advise!