MVC 怎么实现用到哪个js文件,就加载哪个js?

JavaScript06

MVC 怎么实现用到哪个js文件,就加载哪个js?,第1张

要加快网页的加载速度,其实有很多方法。减少包含js也是一种优化手段。

至于MVC只是一种思考的模式,并不具有加载js的方法。

据我所知,可以借助smarty3来实现减少包含js。

理论指导是使用组合的方式,也就是高内聚,低耦合。

举个例子

在A页面需要用到example.js里面的的方法,那么我可以在A页面这样写

<{include file="example.tpl"}>

然后在example.tpl里面加入

<script src="<{$jsUrl}>example.js" type="text/javascript"></script>

尝试了还是不行的原因,你可能在mvc的xml文件中没有引入mvc的配置:

(我的是这个文件:applicationContext-mvc.xml)

1、xmlns:mvc="http://www.springframework.org/schema/mvc"

2、xsi:schemaLocation=“http://www.springframework.org/schema/mvc 

http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd”

3、<mvc:annotation-driven /><!--启动注解驱动 -->

<mvc:resources location="/imgages/" mapping="/imgages/**"/>

<mvc:resources location="/js/" mapping="/js/**"/>

<mvc:resources location="/css/" mapping="/css/**"/>

如此之后,我的就可以了。希望让更多的的人看到

PS:我的项目是Maven构建的Spring+SpringMVC+MyBatis

贴上图片,看的更直观些