HTML 頁面中可放置多組
結論
一個 HTML 頁面中 **<script> 標籤對數量無上限**,可根據需要放置多組。
最佳實務
- **模組化開發**:每個獨立功能/模組對應一個
.js 檔,以 <script src="..."> 引入。
- **避免內嵌大量程式碼**:不要將大量邏輯直接寫在
<script> 內,維護困難且阻塞渲染。
- **載入優化**:
- 使用
defer 或 async 屬性控制執行時機。
- 生產環境合併壓縮為少數幾個 bundle 檔。
範例
<head>
<script src="vendor/jquery.min.js" defer></script>
<script src="vendor/lodash.min.js" defer></script>
<script src="app/main.js" defer></script>
</head>
<body>
<!-- 頁面內容 -->
<script>console.log('inline script');</script> <!-- 偶爾需要的內嵌碼 -->
</body>
- 上一篇文章: iOS 使用 NSJSONSerialization 解析巢狀 JSON 回應資料
- 下一篇文章: 問卷調查網站資料庫設計:動態欄位採用 EAV 或 JSON 方案
Copyright ©
程式碼之家 All Rights Reserved