rmariuzzo / Laravel-JS-Localization

🌐 Convert your Laravel messages and consume them in the front-end!

Home Page:https://github.com/rmariuzzo/laravel-js-localization

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Message keys of generated file is not consistent

rtheunissen opened this issue · comments

We're facing a problem where we version assets based on their content to improve caching. We're compiling on 4 different servers that sit behind a load balancer. Unfortunately, the version hashes of the lang.js files are sometimes different from one server to the next, resulting in 404's if the page and the asset are loaded from different servers.

The reason for this is because the ordering of the encoded json of the messages is not always the same. The only solution I can think of is to recursively ksort the messages so that ordering is consistent.

@rtheunissen Why would it fix the issue? If you haven't changed anything and re-generate js file - ordering will be the same without any sort being performed, isn't it?

I believe that json_encode preserves the ordering of the array. If that is true, then between one server and another, the ordering of $messages is not the same (however that may happen). If we can make that ordering consistent, the json encode will be the same on all servers, and the string replacement for {{ messages }} won't cause the same effective content to generate two different hashes.

This has been implemented in #98

@rtheunissen thank you for your support!