-
-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added assets versioning #12591
Added assets versioning #12591
Conversation
356cfc7
to
8bf8fb3
Compare
Also i think |
8bf8fb3
to
357d09e
Compare
phalcon/assets/manager.zep
Outdated
} | ||
let prefixedPath = prefixedPath . "?ver=" . version; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I dislike such pasta code
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh so let prefixedPath .= "?ver=" . version
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ideologically the version must be a string or null. Not boolean or yet another type.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean i wanted true/false to make it automatic versioning - so version is file modification time as you can see in this code. Don't really see a point in adding seperated method for version from filemtime or something like this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So do you prefer to introduce an entity that means anything instead of 2 specialized methods
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well yea, cuz this will require to https://github.com/phalcon/cphalcon/pull/12591/files#diff-f14ebcff6721de771f55f77e6f962321R96 have another argument too. I mean maybe your solution is better, i can change it, just felt it will be better to have just one method/argument added which can be used for both stuff.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Green-Cat @SidRoberts @Izopi4a @wolftankk @akatasonov what you think above another method?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i find this PR very useful. maybe if this pasta is ugly, we can like in volt services..
$di->set('assets', function(){
$cls = new Assets();
$cls->setAppendString("?ver=".$config->assetsVersion);
return $cls;
}
but as i said, versioning to assets its very important for me.
both cases, i dont think it should matter that much, its nothing un debuggable, its not super hard to understand and we can always change it if some person explain it sux
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like append string. What with auto versioning? What with other version for certain resource etc? I can add other argument and method but it will mean that there will be additional argument - and as you can see in current code it's not necessary really. Shouldn't we keep things simple, stupid instead of adding something which is not needed?
phalcon/assets/manager.zep
Outdated
} | ||
let prefixedPath = prefixedPath . "?ver=" . version; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The same here
I try to refrain from commenting if it's not constructive but this really doesn't belong in the framework. |
Why it doesn't belong in the framework? There is assets manager in framework so why not add versioning to it which is pretty need feature i think(like we wan't people to refresh their js/css)? |
I prefer a more flexible approach. For example Version Strategy (incremental, direct, etc). A separated entity with delegated responsibility. |
How this is not flexible? For resource versioning it depends hardly on Resource itself, cuz in resource is uri generated for certain resources, as well uri for joined resources is generated in collection. |
b3576ee
to
5428fdb
Compare
What we can have:
Do you really want to incapsulate all this in one optional parameter and introduce a pasta factory for it? |
md5/crc32 from content is really bad way for performance. Some example for incremental/explict strategy, what you mean by them? It can't obviously increment itself.... You can either provide version by hand like Right now incremental, explict and timestamp is implemented with this code so i don't see a problem. |
The problem is not that something isn't done. I mean design and single responsibility. |
Do you really like such design? if version != null {
if version {
if version === true {
// ...
}
}
} |
5428fdb
to
57d502e
Compare
So you like more something like: $assets->addJs(PATH_DATA.'assets/script1.js', true, false, null, '1.0.0'); // 1.0.0 version
$assets->addJs(PATH_DATA.'assets/script1.js', true, false, null, null, true); // version from timestamp
$assets->addJs(PATH_DATA.'assets/script1.js', true, false, null, '1.0.0', true); // and here we should have what and why?
? |
I will keep this PR open for a some time to allow other contributors a chance to speak up, and to take a fresh look at it later. |
70647a0
to
d2b7d2b
Compare
Failing tests seems unrelated. |
d2b7d2b
to
deb303e
Compare
ba01336
to
3364d85
Compare
Rebased onto 4.0.x, let me see if tests pass because i don't remember. |
@Jurigag There is few issues with 4.0.x branch. Let me fix them and update the branch |
I guess i need to update tests. I will do it in a few days. |
@Jurigag Assets auto versioning with collection doesn't work correctly. Take a look at - Expected
+ Actual
@@ @@
'<script type="text/javascript" src="/home/travis/build/phalcon/cphalcon/tests/_data/assets/script1.js?ver=1.0.0"></script>\n
-<script type="text/javascript" src="/home/travis/build/phalcon/cphalcon/tests/_data/assets/script2.js?ver=1527660806"></script>\n
+<script type="text/javascript" src="/home/travis/build/phalcon/cphalcon/tests/_data/assets/script2.js"></script>\n
|
Also please use CHANGELOG-4.x and do not change CHANGELOG.md |
* Should version be determined from file modification time | ||
* @var bool | ||
*/ | ||
protected _autoVersion = false { set }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I propose to not introduce anymore _prefixed variables. Lets use autoVersion
instead of _autoVersion
.
/** | ||
* Phalcon\Assets\Resource constructor | ||
*/ | ||
public function __construct(string type, string path, boolean local = true, boolean filter = true, array attributes = []) | ||
public function __construct(string type, string path, boolean local = true, boolean filter = true, attributes = null, var version = null, var autoVersion = null) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Jurigag Do we really need to change attributes type? The Phalcon v4 will have a lot of BC incompatible changes. Could you please try to sort out how to avoid yet another
let version = this->_version; | ||
|
||
if this->_autoVersion && this->_local { | ||
let modificationTime = filemtime(this->getRealSourcePath()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the filemtime is I/O function, which will be called for each request. right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: The results of this function are cached. See clearstatcache() for more details.
https://secure.php.net/filemtime#refsect1-function.filemtime-notes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, right.
Resolved in #14056 |
Hello!
In raising this pull request, I confirm the following (please check boxes):
Small description of change: This change is adding assets versioning setting it either in resource or collection, resource version overrides collection version with option for automatic assets versioning using filemtime.
Thanks