2

Am looking to integrate SquishIt with our webapp. What I have noticed from the testing locally is, SquishIt generates the file only once. Based on other SO answers and reading the SquishIt code I gather that the file generation happens if the HttpCache doesn't contain a value of the generated hashed key.

If without restarting the app, or without clearing the HttpCache, if I delete the generated minified file, then SquishIt doesn't recreate the file.

Is there any way to force SquishIt to recreate the file, if it doesn't exist?

Earlier we were using RequestReduce and we noticed the it didn't always pick up css/js changes if only the css/js files were edited (ie, web.config was not edited and the app was not restarted). To ensure that the changes are picked up, we always delete all generated files when deploying.

  1. Will SquishIt ALWAYS detect the changed code, even if web.config is not modified, the app is not restarted and the HttpCache is not cleared?

    The [BundleCache.Add] (https://github.com/jetheredge/SquishIt/blob/master/SquishIt.Framework/BundleCache.cs#L40-54) method's code helps answer this question

  2. Can I force SquishIt to generated files by simply deleting the generated files?

    After thinking about the scenario I need to handle, this is the wrong question to ask.

EDIT:

  1. What are the cache headers sent to the client for these generated files?

My scenario is as follows. I switched from the default JS minifier to JsMinMinifier. After deleting the files (RenderOnlyIfOutputFileIsMissing is set) and restarting the app, the minified files got generated. However, they had the same name as the previous files (I wrongly assumed it would have a different name).

Refreshing my browser showed that the newly generated files were sent by the server. How did this happen? If the assets had a long expiration cache header set on them, then the browser shouldn't have requested the new file from the server. (Inspecting the assets in Firebug, I am unable to understand the cache policy. To me it looks like it's set to cache for a couple of mins).

EDIT 2:

My take away is, there is no need to delete the generated file to cause regeneration. If the corresponding source files change, SquishIt WILL generate an appropriate file.

Amith George
  • 5,806
  • 2
  • 35
  • 53

1 Answers1

3
  1. It should - we are adding cache dependencies for source files (not the generated ones) so if one of them is edited the entry in the bundle cache should be invalidated. See BundleCache.Add

  2. No - once an entry is in the bundle cache we assume the output file will be there, so you'd end up with the file not being found. This is by design, we haven't really heard a compelling case against it.

Deleting generated files when deploying should be fine though, even if not strictly necessary - don't you need to restart the app then anyway?

If you are really concerned about files lingering you may want to consider using SquishIt without the file system

AlexCuse
  • 18,008
  • 5
  • 42
  • 51
  • Thanks. The `BundleCache.Add` clarified the first issue. Thinking about my second question, I realized I was going at it wrongly. I however have a related third question. I have updated my post with it. – Amith George Jun 13 '13 at 15:05
  • The cache headers are set by IIS' rules for static content, unless you are using the method linked above for using SquishIt without the file system. In that case they are served as dynamic assets and you can control the cache headers from code. – AlexCuse Jun 13 '13 at 16:58
  • Ok, I will read up IIS caching rules. Assuming I had them set to cache for a year, how would I get SquishIt to generate files with a different name (Am using `_#` in the file names to include the hash)? I have changed the minification lib being used, so the content in its minified form is different, but the file name is the same. I understand that the individual unminified script files are the same, but I need to serve slightly different content. – Amith George Jun 14 '13 at 20:08
  • I noticed that if I instead use the `UseNoMinification` fluent method, then it simply concatenates the file, but generates them under a different name. Is there a way to replicate that when using a different minification lib? – Amith George Jun 14 '13 at 20:09
  • Yeah hash in file name (xxxx_#.js) is what you want – AlexCuse Jun 15 '13 at 20:47
  • I understand that. The only change I have made is in the minification library. The original scr files are unchanged. Their file names are unchanged. Thus the hash generated is the exact same as with the earlier minification library. The actual content delivered to user has changed (because of a newer minification lib), but the file name has not. How do I fix this? – Amith George Jun 16 '13 at 16:07
  • The hash is generated based on the minified content of the combined file, not the file names (the hash calculated from file names is used to minimize collision in the bundle cache if the same name is used for multiple bundles). If your rendered file name is not changing, then the content is most likely not changing either. – AlexCuse Jun 16 '13 at 22:04
  • Ok. It's not working for me. However, this issue is not really related to the question I have posted. I will accept your answer to this question, and start another question to discuss why the file names are the same. – Amith George Jun 17 '13 at 22:39
  • http://stackoverflow.com/questions/17158034/squishit-generates-file-with-same-name-even-after-changing-minification-library - Hope to carry forward the discussion via the new question. – Amith George Jun 17 '13 at 22:42