This article describes the method of seajs to force refresh the local cache. Share it for your reference, as follows:
1. Why
Since the user's local cache exists after each uploading the js file to the server, the user needs to force clear the cache or wait for the cache to expire before using the new function, which is extremely unfriendly.
2. Principle
The map attribute in the seajs configuration parameter is the file mapping function, and its function is to map the file loaded through seajs to a new name to load, like
var version="0.0.1"; ({//seajs configuration statementmap:[ [".js",".js?v="+version]//Map Rules] });
Then, the js module introduced through require in modularization or through()
The js loaded asynchronously will be mapped to a new address, like:
require("./a");(["a"]);
Seajs will be loaded without configuring the map attribute. The file name loaded after configuring the map attribute is?v=0.0.1
3. Expand
1. For me, its biggest function is to set the version number globally, which is the method mentioned in the principle, providing a method to force refresh the cache.
2. Of course, this form also found an alternative to - when querying information. This way, the greatest function can be used to replace js and make js use debug version of js, which is quite interesting.
There are many functions in this article that can greatly simplify development or deal with some difficult problems. We need to read them carefully and learn more.
I hope this article will be helpful to everyone's seajs programming.