Call file.size only once and only if necessary

Discovered while profiling (using Chrome) that the file.size property is expensive. This code change optimizes performance by only accessing the 'size' property once and only if needed.