lajax / yii2-translate-manager

Translation Manager
MIT License
227 stars 89 forks source link

LanguageItemPluginAsset forceCopy causes overhead and timestamp change #119

Open rhertogh opened 6 years ago

rhertogh commented 6 years ago

Is it really necessary to force a copy in the LanguageItemPluginAsset?

https://github.com/lajax/yii2-translate-manager/blob/560baa79d6ccaeb1048508f29b3929e5bfd01f23/bundles/LanguageItemPluginAsset.php#L25

This causes overhead in each request and prevents client side caching of the translation file (Yii appends the timestamp, but that changes on every request due to the forced copy)

image

moltam commented 6 years ago

Well it depends.

I think the reason behind it is that this minimizes the possibility of serving an out of date language file. The language file is updated each time when a translation is modified. Without the forceCopy option, the Yii2 AssetManager will not update the file in the web folder (it will only publish once, when it detects that the file is missing), so the translations won't get updated. However if you use the linkAssets => true options in the AssetManager config, this will not be a problem (because of the symlink the file will always contain the latest translations). So you may need it in your specific environment, it depends on how you deal with assets.

Fortunately Yii2 provides a way to change the configuration for an asset bundle. If you don't need the forceCopy, you can turn of like this in the application config:

'assetManager' => [
    'bundles' => [
        \lajax\translatemanager\bundles\LanguageItemPluginAsset::class => [
            'publishOptions' => [
                'forceCopy' => false,
            ],
        ],
    ],
],