On 20/12/2010, at 10:36 PM, Adam Heath wrote:
> Scott Gray wrote:
>> On 20/12/2010, at 10:04 PM, Adam Heath wrote:
>>
>>> Be very careful about combining lots of javascript files into one.
>>> You *must* do proper If-Modified-Since handling, or you will greatly
>>> increase the bandwidth usage of client browsers.
>>>
>>> Without a proper ETag, and If-Modified-Since handling, the browser
>>> will download the combined javascript file repeatedly, on each page
>>> load. The solution, is a bit convoluted.
>>> ==
>>> allETags = []
>>> greatestLastModified = 0
>>> for(file in files) {
>>> perFileETag = perFileLastModifiedTime + '-' + perFileSize
>>> allETags.add(perFileETag)
>>> if (perFileLastModifiedTime > greatestLastModified) {
>>> greatestLastModified = perFileLastModified
>>> }
>>> }
>>> etag = allEtags.join(':')
>>>
>>> response.setHeader('ETag', etag)
>>> response.setLastModifiedTime(greatestLastModified)
>>> ==
>>> and...
>>>
>>> in IMS mode, the previous ETag will be given. Split that on ':',
>>> iterate each part, comparing the lastModifiedTime and size to the
>>> current list of files.
>>>
>>> IMS mode is also different in HEAD and GET mode.
>>>
>>> I suppose I should pull out the Binary handler in webslinger, as it
>>> has support for all of this.
>>>
>>
>> The combined files are written to runtime/tempfiles (tempfiles being a
>> webapp mount point) and only regenerated when the cache entry is removed, in
>> production you wouldn't set an expireTime so they'd essentially only be
>> regenerated if the instance is restarted. No special handling should be
>> necessary, the app or http server would set the headers in the same way it
>> does for the static javascript files.
>
> Why rewrite the combined files into tempfiles at all? Just iterate
> over them each time during serve. No need to use extra disk space.
>
> Would the cache have to cleared anytime one of the member files is
> modified on disk? If so, then ew. That's very sucky.Well you would use a short expireTime for development, same as for a million other things in OFBiz. I'll post the code to jira if anyone wants to use it while they wait for the superior solution. Regards Scott
smime.p7s
Description: S/MIME cryptographic signature
