Yinuo Snowball Technical Blog
website·Indexed 31 days ago
https://blog.yinuosnowball.top/A comprehensive collection of technical notes and guides covering frontend engineering. Key topics include deep dives into Webpack (basic, advanced, and custom loader/plugin implementation), TypeScript fundamentals, design patterns (creational, structural, and behavioral), sorting algorithms, HTTP status codes, browser caching, and mobile development concepts. It also provides practical setup guides for React and Vue CLIs, as well as tool configurations for Prettier and VS Code.
What's inside Yinuo Snowball Blog
- Gitflow is a strict branching model designed for managing large-scale projects and releases. It assigns specific roles to different branches to isolate feature development, release preparation, and emergency maintenance, ensuring that the main production code remains stable while development continues in parallel.
Overview of EditorConfig
EditorConfig is a system for maintaining consistent coding styles (such as indentation, line endings, and character sets) across various editors and IDEs. It consists of a specific file format (.editorconfig) and editor plugins that read these files to override the editor's local settings, ensuring all team members use the same formatting regardless of their tool choice.Overview of Webpack functionality
Webpack is a static asset bundling tool that takes one or more entry files and compiles the project's dependencies into one or more output files called 'bundles' that can run in a browser. By default, Webpack's native capabilities are limited to processing JavaScript ES Modules: in development mode, it compiles ES Modules; in production mode, it compiles ES Modules and minifies the resulting JavaScript code. It cannot process non-JS assets (like CSS) without additional configuration.Understand the three core characteristics of Object-Oriented Programming
Object-Oriented Programming (OOP) is built upon three primary characteristics:
- Inheritance: Allowing a class to inherit properties and behaviors from another class.
- Encapsulation: Bundling data and the methods that operate on that data into a single unit and restricting access to some of the object's components.
- Polymorphism: The ability of different classes to be treated as instances of the same class through a common interface.
Understand Webpack Plugin Architecture
Webpack plugins extend the build process by hooking into specific events triggered during compilation. This event-driven system is powered byTapable, a core library that defines the hook types. Plugins register tasks to these hooks, allowing them to modify resources or change the build behavior at specific stages of the production line.Understand JavaScript Decorators
Decorators are functions used to enhance the functionality of JavaScript classes. They are applied using the@functionNamesyntax and can be used to decorate four specific types of targets: classes, class properties, class methods, and property accessors.Algorithm applications in Vue and React
Modern frontend frameworks rely heavily on specific algorithms and data structures for performance and architecture:
- Virtual DOM Diffing: Both Vue and React use tree-diffing algorithms. Vue 3 specifically utilizes the Longest Increasing Subsequence (LIS) for its diffing process.
- Fiber Architecture: React 16 transforms the component tree into a linked list to enable incremental rendering.
- JSX Parsing: Uses a stack data structure.
- Caching: Module caching and Vue's
KeepAlivecomponent utilize linked lists and LRU (Least Recently Used) caches respectively.
Understand the role of build tools in modern web development
Build tools are necessary to transform modern development code into a format that browsers can execute. They perform the following critical tasks:
- Compilation: Converting frameworks (React, Vue), ES6 module syntax, and CSS pre-processors (Less, Sass) into standard JavaScript and CSS.
- Optimization: Compressing code to reduce file size and improving overall runtime performance.
- Compatibility: Applying polyfills and transformations to ensure the code runs across different browser versions.
Architecture for separating static and dynamic resources with Ali-OSS and CDN
To optimize performance and reduce server load, separate resources into dynamic and static categories:
- Dynamic Resources (e.g., index.html): Deployed to ECS servers. Use HTTP conditional caching (
Cache-Control: private no-cache) to ensure users always retrieve the latest version. - Static Resources: Stored in Alibaba Cloud OSS and distributed via CDN to edge nodes. This reduces server traffic and improves access speed.
CDN Configuration Recommendations:
- Static Assets (jpg, jpeg, png, svg, mp3, txt, json, webp): Set expiration to 365 days with a high weight (99). Add a custom HTTP response header
Cache-Control: max-age=31536000. - HTML Files (html, htm): Set expiration to 0 seconds to prevent caching of the entry point.
- Dynamic Resources (e.g., index.html): Deployed to ECS servers. Use HTTP conditional caching (
Understand TypeScript basic and special types
TypeScript provides several fundamental and special types:
number,string,boolean: Standard primitive types.any: Can be assigned any value and assigned to any other type (exceptnever).unknown: A type-safe alternative toany. A value of typeunknowncannot be assigned to other types (exceptany) without a type assertion or type guard.void: Used for functions that do not return a value. It can be assignedundefined.never: Represents values that will never occur (e.g., a function that always throws an error or has an infinite loop). It is a subtype of every type.undefinedandnull: Specific types for missing or null values.
let num: number = 123; let s: string = '123'; let b: boolean = false; // unknown requires type assertion or check function div(params: unknown) { return (params as number) / 2; } // void for no return value function wel(): void { console.log(123); } // never for functions that never return function fn(msg: string): never { while(true) { console.log(msg); } }CI/CD Pipeline for Ali-OSS and ECS Deployment
When configuring a Jenkins pipeline for this architecture, follow this sequence to ensure zero-downtime resource availability: build the project, upload static assets to OSS, and finally package the HTML for ECS deployment.# Example Jenkins steps yarn install --registry=https://registry.npm.taobao.org yarn build:prod # Build production bundle yarn oss --config alioss.production.js # Upload static assets to OSS first tar -zcvf dist.tar.gz dist # Package for ECS deployment (index.html)Understand the Same-Origin Policy and CORS
A cross-origin HTTP request occurs when a resource is requested from a different domain, protocol, or port than the one where the resource is hosted. Browsers restrict cross-origin HTTP requests made via scripts (XMLHttpRequest and Fetch API) for security reasons unless the server provides specific CORS (Cross-Origin Resource Sharing) headers. Browser restrictions can manifest in two ways: preventing the request from being sent if a preflight check fails, or blocking the response from being read by the script even if the request was successful.