How can ClientDependency automatically reload files when they are changed?

Jun 6, 2012 at 8:11 AM
Edited Jun 6, 2012 at 8:14 AM

When the framework is combining and minifying, it doesn't seem to pick up changes in stylesheets and scripts. You have to delete the temporary files or update the version attribute in web.config.

Imho that shouldn't be necessary in a framework like this, so I would expect there's a switch to turn this behavior into something more conventional.

Is there?

Something like: <clientDependency version="auto"> could just append a timestampe of the laste changed file in a set as the version.

Coordinator
Jun 20, 2012 at 4:53 PM

In order for this to work we would need to scan for file changes and create a hash of those files. Unfortunately doing this isn't so easy since the files can be located anywhere and we'd have to use a Timer or something to facilitate this because of medium trust.

We would also need to persist this version somewhere outside of the config file (a regular xml file or something) since changing the config file will restart the app pool.

You can turn off the persistence of files in the config which means it will not put any files in the cache and you won't run in to issues with those files but it does mean you'll have to bump your web.config when files are changed because the outputcache of the already rendered files will need to be cleared. However, the version will remain the same which means that external clients will not be forced to download the new versions.

Having an 'auto' version could be really awesome, but just need to figure out the best way to achieve this without causing any performance issues. Because of Medium trust support i can only think that having a Timer to scan all registered files and create a hash is the only way to go but don't know if this will cause perf issues... maybe not!?

Jun 20, 2012 at 9:39 PM

When you combine and minify the files the first time, you know exactly where they are, right? So at that moment, you'd have to save the list of file names along with the date and time of caching.

On every request, you could check for each file if it has been changed since the last time it was cached. If it was, then you'd need to invaliate the cache and recombine an minify the set. If no file has been changed, then just serve the set from the cache. 

So I don't think you'd need to use a timer (it's only needed to refresh the cache when there's an actual request), and medium trust should not be an issue.

The only issue would seem to be the extra effort required to scan for file changes on every request. I'm not sure how much of a negative impact that would have on performance. But with a setting like version="auto" developers can weight the benefits for themselves.

Do you want me to try prototyping this in a fork so you can test it?

Coordinator
Jun 22, 2012 at 2:36 PM
We do have a reference to all the files as you suggest but we cannot rescan all of these files on each request as this will not perform very nicely. If you are getting a lot of requests per second then this will of course not be very nice whereas with a timer we can ensure that the scan only happens once every few seconds or whatever. Also when CDF renders out the results of a dependency request it Output Caches the result based on the URL so no handler actually fires after the first request.
Happy for any prototypes though, that'd be kick ass!

Cheers Shannon




On Wed, Jun 20, 2012 at 11:39 PM, michielvoo <notifications@codeplex.com> wrote:

From: michielvoo

When you combine and minify the files the first time, you know exactly where they are, right? So at that moment, you'd have to save the list of file names along with the date and time of caching.

On every request, you could check for each file if it has been changed since the last time it was cached. If it was, then you'd need to invaliate the cache and recombine an minify the set. If no file has been changed, then just serve the set from the cache.

So I don't think you'd need to use a timer (it's only needed to refresh the cache when there's an actual request), and medium trust should not be an issue.

The only issue would seem to be the extra effort required to scan for file changes on every request. I'm not sure how much of a negative impact that would have on performance. But with a setting like version="auto" developers can weight the benefits for themselves.

Do you want me to try prototyping this in a fork so you can test it?

Read the full discussion online.

To add a post to this discussion, reply to this email (clientdependency@discussions.codeplex.com)

To start a new discussion for this project, email clientdependency@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe on CodePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at CodePlex.com