Closed petrabarus closed 8 years ago
Is it ready info-wise? I can simplify the wording.
Yes I think it's ready. In short there are two simple steps:
hashCallback
that doesn't depend on time.Yeah,,, I really overdid it. LOL. If you want to simplify the wording, I'd be glad. But I think I need to cover why the steps in this article is too simple and what things it overlooked.
@petrabarus Nice write up. I think the wording is fine tbh as this is somewhat of a complex topic, I'll hopefully get around to contributing somethings to it too.
Couple of things I wanted to bring up regarding the asset management. First, we probably want to give further examples, rather than just showing an closure you could show something along the lines of this
$config = [
'components' => [
'assetManager' => [
'hashCallback' => function ($path) {
return hash('md4', $path);
}
]
]
];
The other thing is regarding the cache-busting technique of including Yii::$app->version
implies that the user will need to update this version property on each change (or have it updated by the deployment process potentially), I think a better solution is to use the $appendTimestamp property of the AssetManager
class like so.
$config = [
'components' => [
'assetManager' => [
'appendTimestamp' => true,
'hashCallback' => function ($path) {
return hash('md4', $path);
}
]
]
];
This will result in asset URLs like this /assets/2445dd2999f135ab39ac4fa59f522464/css/global.min.css?v=1464130501
@badams
Yes the $appendTimestamp
can work! I forgot that it exists. It won't work well in more complex situation as in mine. But in this case it's good enough. Thanks!
Awesome write up! It's indeed a complex subject that deserves some context.
Another possible (simple) solution might be storing the asset files in the cloud i.e. S3 or Google Cloud Storage, and then defining a path alias like @cloud
to the base storage URL. Would that be efficient?
Storing asset in S3 or Cloud Storage is a very good solution, but it's more efficient if you do it using build server instead in production server. I think we should also cover about continuous integration. I've started a WIP #118. Let me know if you have any ideas.
@badams Updated.
Although I just realized that if we don't set forceCopy
in the asset manager, updated asset won't be published because there is already existing old copy.
Merged. Thank you very much!
If you have further changes, please open more pull requests.
@samdark It seems that I overdo the asset management part. It's more complex than the previous sections.