requirejs为何会多次加载两次data-main文件


html页面:


 <!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>require-demo第一章</title>
</head>
<body>
    <script type="text/javascript" defer async="true" data-main="js/app" src="js/require.js"></script>
</body>
</html>

app.js页面:


 requirejs.config({
        // baseUrl:'js/lib',
        paths:{
            avalon:'bower_components/avalon/min/avalon.min',
            avalondate:'bower_components/avalon.oniui/datepicker/avalon.datepicker'
        }
    });

requirejs(['avalon','avalondate'],function(){
})

问题
1、当把script放置head元素标签中时,加载无问题


 <!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>require-demo第一章</title>
    <script type="text/javascript" defer async="true" data-main="js/app" src="js/require.js"></script>
</head>
<body>
</body>
</html>

图片描述
2、当把script放置body元素标签时,会重复加载data-main右侧的文件


 <!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>require-demo第一章</title>
</head>
<body>
<script type="text/javascript" defer async="true" data-main="js/app" src="js/require.js"></script>
</body>
</html>

图片描述
文件目录
文件目录

avalon requirejs

知道才有鬼 9 years, 8 months ago
        [该用户已被屏蔽]
cuaznu answered 9 years, 8 months ago

Your Answer