Abstract:
[Opensource] scriptloader: After the release of your JS class library is easily managed, some garden friends reflect that the intrusion is still a little too strong. I thought of a good idea in the middle of the night. The more I thought about it, the more I couldn't sleep. I finally got up and upgraded scriptloader to V2. This version will give you a more convenient experience in organizing script files, added Automatic Association, multi-language support, and attractive syntactic sugar. Using scriptloader will change your previous programming habits ^_^.
Introduction:
Scriptloaderv2 adds some new features:
- There is no invasive script introduction mechanism for Aspx.
- Multi-language resource support.
- It makes it easier for you to load the syntactic sugar of the module.
No intrusion script introduction mechanism:
The current script organization method is generally that each aspx will introduce some JS core class libraries through the script tag, and then mix some business logic scripts required for the current page in the ASPX page.
As a result, JS is closely integrated with our aspx, which is not conducive to the maintenance of the entire project. To solve this problem, scriptloader provides an httpmodule for JS introduction. When you read webform1.aspx, it will automatically help you load webform1.aspx in the same directory. JS files, because they are imported through scriptloader, have the characteristics of scriptloader, such as cache, as long as your webform1.aspx. if the last modification date of JS is not changed, the client cache can be used all the time.
However, you may think of the following situation:
We often use <% = This. txtname. clientid %> This method is used to obtain the unique ID of the server control on the client. In this case, JS introduced externally cannot be used. Therefore, I introduced the second feature of scriptloaderv2.
Multi-language resource support:
Use the scriptloader. setvariable method to assign values.
Related methods include:
If you use this feature, it will be invasive. If you do not want to be invasive, you can also use the original ASP. NET method:
What is the relationship between this feature and multiple languages?
Because one of these methods is to read the xml configuration file and directly set variables, XML is as follows:
ReadCode:
Therefore, if you want to assign different values to these variables based on different languages, you can write a few more config, such as myVars-en-US.config, myVars-zh-cn.config, and then load different variables according to different language versions, in JS, variables are used to replace character constants in multiple languages.
Of course, there is a better integration method, that is, to change the page organizational structure to the following form:
Then, just like the first feature, it automatically loads different JS or config files based on the language version. This feature is not added at present, because there is no way to consider some special situations, so you are not yet ready to add this feature, but this modification is also very fast. If you need it, you can download the code and modify it yourself. If you can feedback your application to me, that would be better. When the time is ripe, I will consider directly integrating the code into scriptloader.
The variable problem is solved, but the Js of each business logic cannot leave some core JS class libraries, such
I need to introduce the jquery class library on the current page. What should I do? To solve this problem, scriptloader adds the third feature.
Syntactic SUGAR:
The so-called syntactic sugar is a clever practice, a bit like the automatic attribute in vs2008
In fact, this is not a feature supported by the standard language library. It is a convenient channel provided by vs2008 IDE. In scriptloader, similar features are added to solve the problem of introducing scripts:
We can see that the header in webform2.aspx. js uses the using method and introduces three JS modules configured in Lib. config.
This syntactic sugar can only be used in webform2.aspx. in JS, not all JS class libraries can be used. scriptloader analyzes and automatically loads these modules when injecting scriptloader to the aspx page. The core class library must still be configured through Lib. config/user. config, so that you can use using (modulename) to introduce these scripts.
Postscript:
I am a title party. Don't approve my title.
If you use these features of scriptloader, it can indeed improve the experience of many JS file organizations. Currently, most JS class libraries are more concerned with function encapsulation, but little attention is paid to the organization and management of JS files. scriptloader is designed to fill this gap.
More exciting features will be added in later versions, such as clientcachemanager.
Examples is included in the SRC release package. You can also use SVN to obtain the latest version of scriptloader.
Http: // www.sourceforge.net/projects/scriptloader