Carabiner 1.4: Asset Management Library |
[eluser]polyvoid[/eluser]
I couldn't resist fiddling with it a bit more. As far as I can tell the "javascript" part works. I've tested it, and it works for me now. I did it with an additional if which checks if it's an url from another domain, or if it's coming from the filesystem, and use the according "get" function then. I did not change the "styles" part (yet), as usually these are coming from the filesystem. Perhaps, for the sake of consistency, you could make the changes as well. The changed file is attached to this post so you can find out if it's alright. The changes are marked as comments with "start change" and "end change"
[eluser]tonydewan[/eluser]
It looks like you have this figured out. I will add cURL support to my list of changes for the next version. Great find!
[eluser]polyvoid[/eluser]
Yes, thanks. Another thing I cannot figure out: I use to put all my CSS files between the head tags, and put all my javascript files just before the closing body tag. (this is best practice for performance; see -> http://developer.yahoo.com/performance/rules.html) When using groups in carabiner, I cannot see a way to do this. Is this possible?
[eluser]tonydewan[/eluser]
If you've only got JS files defined in a group, then displaying that group will only show JS files. If, however, you've defined both CSS and JS in a group, there is currently no way to de as you've asked. I will add support for that in the display function in the next version. In the meantime, I would split your group by asset type. Meaning, if you had Code: $this->carabiner->display('groupname'); Code: $this->carabiner->display('groupname-js');[ In terms of adding support for this in the future, my thought would be to add the option for a second parameter to the display function for asset type, and let that filter what is displayed. For example: Code: $this->carabiner->display('groupname','js');
[eluser]polyvoid[/eluser]
Yes, that would solve it definately! Can't wait until your next version is released. Will the "return as string" functionality for the display function be included in the next version as well? Is there any way to be informed when another version is ready, or should I check the wiki once in a while?
[eluser]tonydewan[/eluser]
Return as string will be included. The best way to keep informed would be to stay notified about this thread changing. Whenever I release a new version, I add a reply to the previous versions thread announcing it and linking to the new forum post.
[eluser]MindFeed[/eluser]
Hey that’s awesome library, thanks for thinking about and creating it. I recently started using your library, except for first time when it cache the files, it has a drastic effect on JS/CSS transferring time. Initially I implemented the library on stand alone server and it worked exactly what we have expected. But when we have tried it on Load Balancer, it failed because of different name of file on each server and request being distributed among several HTTP servers. By the way do you have any thoughtful way out to resolve Load Balancer issue ? It will be great if you have any patch ready to implement this library on Load Balancer, looking forward to it. Thanks, Bhargav Khatana
[eluser]dmorin[/eluser]
How are you deploying your site to the servers? If you're using rsync or some similar tool, you should be using the option to retain the original modified date. This way, the modified date would be the same across all servers so all of the file names would be the same. The other option is to of course rely on you central persistence layer to store the current file versions, but this is a big step away from where carabiner is so I'm not sure you'll find anyone making a patch for it here.
[eluser]tonydewan[/eluser]
I replied at your first thread, but I'll reply here as well. @dmorin is right. Here is some more info: The filenames that Carabiner creates are a concatenation between the last-modified-time (filemtime in PHP) of the most recently modified file, and an MD5 hash of all of the asset filenames (in the group) put together. I'm assuming, then, that the part of the filename that is different is the filemtime string. If that is indeed the problem, a simple (but not necessarily scalable) solution (assuming you're on Unix) would be to run this command on whatever the most recently modified file is, BEFORE Carabiner runs (i.e.: when you deploy to the load balanced servers): Code: touch -mt 0711171533 /PATH/TO/ASSETFILENAME.js where 0711171533 is a Unix timestamp. This is obviously not a scalable solution. Otherwise, you'll need to come up with a better way to create unique filenames, or store the filenames in a database. In the case of the former, let me know if you come up with something. In the case of the latter, I would store the MD5 hash as your key, and then when a new file is created, store that filemtime. Then, every time a file is to be created, check for the hash, and if the filemtime is less than an hour (or whatever) older than the one you have, use the one from the DB. Of course, that puts a lot more load on the database, which in the long run is not the best plan, and not one I would recommend. In terms of the solution hinted at by @dmorin, I'm not even sure I completely understand it. However, if I do, a simple solution would be to reference the assets by URL (that is, the url on your central persistence layer). You would lose the filemtime string (which Carabiner fills with zeros when all files are remote to maintain filename length consistency) on the combined file, meaning you would need to manually empty the cache when changes are made. If I come up with something better, I'll let you know.
[eluser]MindFeed[/eluser]
Thanks for your thoughts into the problem. Though if I keep the file name same, the problem stands as it is. As each and every request has been distributed among 5 apache servers through load balancer, if LB hit the first server for getting the PHP->HTML page, it might hit any of 5 server for loading various resources like images, css, javascript. So in this case only first server has the combined/minified javascript/css files and not other servers and hence response will be 404 with the rest of 4 servers, unless and until LB hit that server for PHP->HTML page. Just preliminary thoughts towards solution: => Lets store the combined/minified version to DB, centrally accessible to all the servers. => Table will have four fields, asset_key, asset_type, asset_content, asset_dt => Store filename in asset_key (without extension, jst lastmodified + md5(filenames)), ‘js’ or ‘css’ in asset_type, combined and minified version to asset_content, and timestamp to asset_dt => In library we will check filename against asset_key in database instead of checking file on hard drive. => Modify _cache function to write into database instead of writing on disk => Modify _tag function where instead of including the combined/minified version of javascript/css from cache directory, will include path to controller/function which in turn read the database and echo the content with proper heading. => In that controller/function, I also can set proper caching header, after checking ETag and IF-Modified-Since howz that! Thanks, Bhargav Khatana |
Welcome Guest, Not a member yet? Register Sign In |