简体   繁体   English

如何从一个html文件加载所有脚本和链接?

[英]how to load all scripts and links from one html file?

In JSPs, I normally use two files that are included on all pages by simply doing: 在JSP中,我通常只需做以下操作即可使用所有页面中都包含的两个文件:

<%@include file="include/include.jsp"%>
<%@include file="include/imports.jsp"%>

include.jsp contains the following content: include.jsp包含以下内容:

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@ taglib prefix="s" uri="http://www.springframework.org/tags" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags"%>

imports.jsp has the following: imports.jsp具有以下内容:

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="Content-Script-Type"
content="text/javascript; charset=UTF-8" />

<link rel="stylesheet" href="${pageContext.request.contextPath}/static/css/app.css"
type="text/css" media="screen" />       
<link rel="stylesheet" href="${pageContext.request.contextPath}/static/css/bootstrap.css"
type="text/css" media="screen" />
<link rel="stylesheet" type="text/css" href="//cdnjs.cloudflare.com/ajax/libs/font-awesome/4.2.0/css/font-awesome.css" />

<link rel="stylesheet"
href="${pageContext.request.contextPath}/static/css/bootstrap-responsive.css"
type="text/css" media="screen" />
<link rel="stylesheet"
href="${pageContext.request.contextPath}/static/css/datepicker.css"
type="text/css" media="screen" />
<link rel="stylesheet"
href="${pageContext.request.contextPath}/static/css/flip-tabs.css"
type="text/css" media="screen" />
<link rel="shortcut icon" href="${pageContext.request.contextPath}/static/images/favicon.ico" /> 

<script src="${pageContext.request.contextPath}/static/js/jquery-1.12.1.min.js" ></script>
<script src="${pageContext.request.contextPath}/static/js/bootstrap-datepicker.js" ></script>
<script src="${pageContext.request.contextPath}/static/js/jquery.quickflip.min.js" ></script>

With those two files included, I can access all scripts and taglib on the page I'm working on. 有了这两个文件,我就可以访问正在处理的页面上的所有脚本和taglib。

Since I've worked almost exclusively with JSPs, I'm new to HTML5 and would like if it's possible using the same approach on all my html pages. 由于我几乎只使用过JSP,因此我是HTML5的新手,并希望在所有html页面上使用相同的方法。 If so, how? 如果是这样,怎么办?

In order to load an HTML file, add a link tag with an import in the rel attribute and an href that contains a path to the HTML file. 为了加载HTML文件,请在rel属性中添加一个带有import的链接标签,并在href中包含HTML文件的路径。 For example, if you want to load an HTML file called component.html into index.html: 例如,如果要将一个名为component.html的HTML文件加载到index.html中:

index.html index.html

**<link rel="import" href="component.html" >**

You can load any resource including scripts, stylesheets, and web fonts, into the imported HTML just like you do to regular HTML files: 您可以像导入常规HTML文件一样将任何资源(包括脚本,样式表和Web字体)加载到导入的HTML中:

component.html component.html

**<link rel="stylesheet" href="css/style.css">
<script src="js/script.js"></script>**

doctype, html, head, body aren't required. 不需要doctype,html,head,body。 HTML Imports will immediately load the imported document, resolve sub resources and execute JavaScript, if any. HTML导入将立即加载导入的文档,解析子资源并执行JavaScript(如果有)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM