yii2-translate-manager icon indicating copy to clipboard operation
yii2-translate-manager copied to clipboard

LanguageItemPluginAsset forceCopy causes overhead and timestamp change

Open rhertogh opened this issue 6 years ago • 1 comments

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

rhertogh avatar Apr 24 '18 18:04 rhertogh

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,
            ],
        ],
    ],
],

moltam avatar Apr 26 '18 19:04 moltam