Example of using RequireJS library in ASP. NETMVC Project _ javascript skills

Source: Internet
Author: User
This article mainly introduces ASP. the use example of RequireJS in the netmvc project. This article mainly describes some basic directory structure ideas of the website project and provides an example of semi-automatic compression, for more information, see RequireJS. It is a popular front-end modular development tool. It is a Javascript library file, that is, require. js.
Main functions of RequireJs:

(1) asynchronous loading of js files to prevent webpage response loss;

(2) Management Module dependencies to facilitate code compilation and maintenance.

Front-end modular development now has a lot of tools, which are generally divided into two categories, one is a high-definition such as dojo, after dojo v1.8 has built-in modular development components, and the other is like require. js, sea. js is a tool dedicated to modular development.

The rules of modular division are divided into AMD and CMD. dojo and require. js follow the former, while sea. js follows the CMD standard.

Require can be used in single-page applications. However, for traditional multi-page applications, it may be confusing and inconvenient to use require.

This article explains how to apply require in the structure of ASP. net mvc and provides a compression script to achieve semi-automatic compression.

Separate js Code
Generally, a route of ASP. net mvc corresponds to a view. The file structure of the view may be as follows:


Views |--Shared |--_layout.cshtml |--Home |--Index.cshtml |--Blog |--Create.cshtml |--Edit.cshtml |--Detail.cshtml |--Index.cshtml

Assume that _ layout. cshtml is shared by all pages. In general, we will reference common js class libraries such as jQuery and bootstrap in _ layout, so that other pages do not need to reference these class libraries again, the encoding efficiency is improved. However, different pages will eventually depend on different js, especially the custom js that implements the page function, so we have to reference special js in other pages, js is even written directly on the page. For example, the following code is often displayed in the View:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.