javascript - 使用 require 的库结构

标签 javascript jquery performance

我不确定如何称呼这个问题,所以欢迎任何修改!!!我正在努力学习保持第三方脚本以及我自己的脚本的干净 js 库结构。除了旧方法之外,除了将 js 文件添加到我的页面的基本方法外,我一无所知。

我在搜索时发现了这个,看到我不太擅长 javascript 或 jquery 这对我来说很有意义 https://github.com/volojs/create-template

我的问题是我的文件夹结构如下

  • index.html
  • Assets /js/lib/gsap/
  • Assets /js/lib/bootstrap/
  • assets/js/lib/whateverelse

在我的 index.html 文件中,我有指向 jquery 和名为 app.js 的文件的链接

但我对如何让它工作感到困惑,如何从目录中调用文件?

基本上我想从 1 个文件调用多个 js 文件

最佳答案

如果我理解正确,你需要 app.js 中包含的文件和 index.html 中包含的 app.js。

app.js

function dynamicallyLoadScript(url) {
var script = document.createElement("script"); // Make a script DOM node
script.src = url; // Set it's src to the provided URL

document.head.appendChild(script); // Add it to the end of the head section of the page (could change 'head' to 'body' to add it to the end of the body section instead)
}
dynamicallyLoadScript('assets/js/lib/bootstrap/test.js');
dynamicallyLoadScript('assets/js/lib/gsap/test.js');

index.html

<script src="app.js"></script>

函数取自here . Guy 几乎回答了所有相关问题。

关于javascript - 使用 require 的库结构,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50767218/

相关文章:

javascript - AZERTY 与 QWERTY 上的键码检测

javascript - 如何在本地存储中的页面刷新时显示图像

javascript - 将选择多个输入转换为 bool 数组

jquery - 如何让我的按钮一次显示一项?

wpf - 慢速组合框性能

javascript - 开始日期晚于结束日期的两个日期之间的差异

javascript - 开 Jest ,如何忽略特定文件夹的测试覆盖率?

javascript - Bootstrap轮播图像调整服务器端大小

Haskell 的性能改进

c# - 为什么在 C# 中使用结构 Vector3I 而不是三个整数要慢得多?