JavaScript
很多教學使用button on click點擊啟動行為常常用
<button onclick="myFunction()">Try it</button>
這種寫法,但是onclick="myFunction()寫法有資安上問題,所以六角線上課時老師建議用 document.getElementById方式去啟動Function()
貼上w3cshool範例點進去有效果展示
<html>
<body>
<p>This example uses the HTML DOM to assign an "onclick" event to a p element.</p>
<p id="demo">Click me.</p>
<script>
document.getElementById("demo").onclick = function() {myFunction()};
function myFunction() {
document.getElementById("demo").innerHTML = "YOU CLICKED ME!";
}
</script>
</body>
</html>
使用addEventListener監聽觸發
In JavaScript, using the addEventListener() method:
<html>
<body>
<p>This example uses the addEventListener() method to attach a "click" event to a p element.</p>
<p id="demo">Click me.</p>
<script>
document.getElementById("demo").addEventListener("click", myFunction);
function myFunction() {
document.getElementById("demo").innerHTML = "YOU CLICKED ME!";
}
</script>
</body>
</html>
暸解單元測試 一次搞懂單元測試、整合測試、端對端測試之間的差異 E2E測試 前端測試原來沒這麼單純 Unit test 與 Integration test 概論 Day 28:前端測試入門 過高的 Test Code Coverage 將摧毀一個新專案 BDD/TDD差別是什麼? 手把手用 Cucumber 實作示範BDD TDD 開發五步驟,帶你實戰 Test-Driven Development 範例 Day 28:前端測試入門
May 17, 2023You can use the Cache Storage API to download, store, delete or update assets on the device. Then these assets can be served on the device without needing a network request. 您可以使用緩存存儲 API 下載、存儲、刪除或更新設備上的資產。然後,無需網絡請求即可在設備上提供這些資產。 Cache storage is a powerful tool. It makes your apps less dependent on network conditions. With good use of caches you can make your web app available offline and serve your assets as fast as possible in any network condition. As mentioned in Assets and Data you can decide the best strategy for caching the necessary assets. To manage the cache your service worker interacts with the Cache Storage API. 緩存存儲是一個強大的工具。它使您的應用減少對網絡條件的依賴。通過良好地使用緩存,您可以使您的 Web 應用程序離線可用,並在任何網絡條件下盡快為您的資產提供服務。如資產和數據中所述,您可以決定緩存必要資產的最佳策略。要管理緩存,您的 service worker 會與 Cache Storage API 交互。 Source
Jan 11, 2023Service workers are a fundamental part of a PWA. They enable fast loading (regardless of the network), offline access, push notifications, and other capabilities. Service Worker 是 PWA 的基本組成部分。它們支持快速加載(無論網絡如何)、離線訪問、推送通知和其他功能。 Users expect apps to start on slow or flaky network connections, or even when offline. They expect the content they've most recently interacted with, such as media tracks or tickets and itineraries, to be available and usable. When a request isn't possible, they expect the app to tell them instead of silently failing or crashing. And users wish to do it all quickly. As we can see in this study Milliseconds make millions, even a 0.1 second improvement in load times can improve conversion by up to 10%. In summary: users expect PWAs to be reliable and that's why we have service workers. 用戶希望應用程序在網絡連接緩慢或不穩定時啟動,甚至在離線時啟動。他們希望他們最近接觸過的內容(例如媒體曲目或門票和行程)可用且可用。當請求不可行時,他們希望應用程序告訴他們,而不是默默地失敗或崩潰。用戶希望快速完成這一切。正如我們在這項研究中看到的那樣,以毫秒為單位,即使加載時間縮短 0.1 秒,也可以將轉化率提高多達 10%。總結:用戶希望 PWA 可靠,這就是我們擁有 Service Worker 的原因。 Hello service workers
Jan 11, 2023Welcome to Learn Progressive Web Apps! This course covers the fundamentals of Progressive Web App development in easy-to-understand pieces. Over the following modules, you'll learn what a Progressive Web App is, how to create one or upgrade your existing web content, and how to add all the pieces for an offline, installable app. Use the menu pane to navigate the modules. (The menu is at left on desktop or behind the hamburger menu on mobile.) You'll learn PWA fundamentals like the Web App Manifest, service workers, how to design with an app in mind, what's different from a classic web app, how to use other tools to test and debug your PWA. After these fundamentals, you'll learn about integration with the platform and operating system, how to enhance your PWA's installation and usage experience, and how to offer an offline experience. Each module includes interactive demos and self-assessments for you to test your knowledge. You will be able to test and try demos on your mobile phone, tablet, or laptop while playing with code to understand the fundamentals of what makes a Progressive Web App. This course is created for a beginner and advanced web developers alike. You can go through the series from start to finish to get a general understanding of PWA from top to bottom, or you can use it as a reference for specific subjects. For those new to web development you will need a grounding in HTML, CSS, and JavaScript to follow along. Check out Learn CSS, and the HTML and JavaScript courses on MDN.
Jan 11, 2023or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up