当前位置:网站首页>JS resource disaster recovery
JS resource disaster recovery
2022-06-21 09:14:00 【Tie Hanhan plus】
JS Resource disaster tolerance
In order to speed up the first loading of the project , Sometimes we use some online plug-ins to introduce ( for example cdn Introducing plug-ins ), But online plug-ins will inevitably have some inevitable problems , For example, the plug-in server crashed 、 The plug-in will not be updated for a long time , All these will cause the online plug-ins introduced by the project to fail to work properly , This may cause the project to fail to work properly . therefore ,js Disaster recovery of resources is still very necessary .
Ideas
stay script Add a onerror Method , When online resources fail to load , stay onerror Method to manually add static js resources
Concrete realization
Let's introduce clipboard plug-in unit To test
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<!--js Methods that fail to load need to be defined in advance -->
<script> function jsLoadErr (e, s) {
console.log(e, s) alert('js Loading failed ') var new_s = document.createElement('script'); new_s.setAttribute('type', 'text/javascript'); new_s.setAttribute('src', s); var head = document.getElementsByTagName('head')[0]; head.appendChild(new_s); // Remove the failed online load script e.remove(); } </script>
<!-- Will be online src Deliberately change the address of the failed access to test -->
<!-- Right online src Address :https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/2.0.6/clipboard.min.js-->
<!--cdn load js When you fail ,onerror Method will automatically load static resources -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/2/clipboard.min.js" onerror="jsLoadErr(this, 'static/pulugins/clipboard/clipboard.min.js')"> </script>
</head>
<body>
<h1 class="test">js disaster </h1>
<script> window.onload = function () {
var clipboard = new ClipboardJS('.test') console.log(' clipboard ', clipboard) } </script>
</body>
</html>
边栏推荐
- Post process basic notes (important items)
- Talking about Festinger effect
- Binary search (integer binary)
- R language uses as The date function converts a single character variable to date data and specifies the format of the data format conversion
- R language through rprofile Site file, custom configuration of R language development environment startup parameters, shutdown parameters, configuration of R startup output custom text and system time
- The next stop of Intelligent Manufacturing: cloud native + edge computing two wheel drive
- Alibaba P6 employees came to a small company for an interview and asked for an annual salary increase of 500000 yuan. How dare you speak
- Common basic functions of R language: call the data editor with edit function to manually customize and edit the data object without changing the content of the original data object, and call the data
- 应用配置管理,基础原理分析
- stm32mp1 Cortex M4开发篇13:扩展板按键外部中断
猜你喜欢

Observation on the salary data of the post-90s: poor, counselled and serious
![[Mgt] model Mgt for code interpretation](/img/4f/694e7b93626436007021b718ad69b5.png)
[Mgt] model Mgt for code interpretation

Audio immersive experience

Lei niukesi --- basis of embedded AI

Tidb3.0- 4.0 memory control / modification log saving days / maximum index length

It is only seven days since the commencement of construction in 2022. I left the outsourcing company

【实战】STM32 FreeRTOS移植系列教程4:FreeRTOS 软件定时器

tidb4.0.0遇见的问题、报错总结(tiup部署)

The internal structure of MySQL and how an SQL statement is executed

stm32mp1 Cortex M4开发篇9:扩展板空气温湿度传感器控制
随机推荐
sql查看数据库/表磁盘占用情况,杀死进程终止tidb中的连接
R language list data object, create list data object, index list data with [[], list data practice
Merge sort of sorting
A command starts the monitoring journey!
Leetcode: print the common part of two ordered linked lists
Abstractqueuedsynchronizer (AQS) source code detailed analysis - semaphore source code analysis
The skill of using ADB and the principle of USB communication
【实战】STM32 FreeRTOS移植系列教程4:FreeRTOS 软件定时器
Storage of C language integer in memory
Three key directories in R language and their corresponding priorities: R_ Home directory, user directory, current working directory, files read by R's startup process
Unity Detailed explanation of meta file function
The spring recruitment is also terrible. Ali asked at the beginning of the interview: how to design a high concurrency system? I just split
Retrofit extended reading
南京理工大学MOOC慕课:程序设计基础(Ⅰ)第8章测试选择题答案及解析
Abstractqueuedsynchronizer (AQS) source code detailed analysis - condition queue process analysis
Base de données de sauvegarde DumpLiNg
stm32mp1 Cortex M4开发篇11:扩展板蜂鸣器控制
声临其境 — 音频沉浸体验
STL教程2-MyArray框架实现
android 数据库升级