Slice caching in pure javascript