flask:在特定模板中加载 JS 库,而不是在基本模板中加载

flask: Loading JS libraries in specific templates over loading in base template

提问人:JeffP 提问时间:10/31/2023 更新时间:10/31/2023 访问量:19

问:

假设我有一个应用程序,而 Flask 是一个微型 Web 框架,我转向渲染我的表格(当然是用)。Flaskdatatablesjquery

现在我的模板如下:

base.html (base template for all other templates)
index.html
other templates
users.html (this is the only template that uses datatables)

习惯上将使用的 JS 链接到模板。现在,考虑到只有一个 () 使用数据表( 和 ),如果我只在 users.html 中加载 jquery 和数据表,它会在加载时间方面对我的应用程序有益吗?base.htmlusers.htmldatatables.jsjquery

目前,我正在基本模板中加载 JS 库。我还没有尝试对加载时间进行基准测试。

jQuery python-3.x Flask 数据表

评论

0赞 Daviid 10/31/2023
为什么要在每个页面中加载数据表 javascript,即使它没有被使用?请注意,影响很可能可以忽略不计,所有插件都缩小的数据表的 CSS+JS 略低于 3MB,但如果您关心定位、SEO、第一个字节的时间和所有这些废话,您可能不想每一页都加载它。
1赞 JeffP 10/31/2023
@Daviid,你的意思是我应该只在 ?users.html
1赞 Daviid 10/31/2023
你应该只在你要使用它的地方加载一个 JS 库。

答: 暂无答案