• 简单静态网站搭建——http


    基础插件应用

    const path = require('path');

    const fs = require('fs');

    const url = require('url');

    const http = require('http');

    const mime = require('mime');

    =========================

    创建服务器

    const app = http.createServer();

    ============================

    app.on('request', (req, res) => {

    //res.end('hello');

    console.log(url.parse(req.url));

    let { pathname } = url.parse(req.url);

    if (pathname === '/') {

    pathname = '/index.html';

        }

    let absPath = path.join(__dirname, 'public', pathname);

    console.log(absPath);

    let type = mime.getType(absPath);

    fs.readFile(absPath, 'utf8', (err, data) => {

    //不存在当前页面

    if (err !== null) {

    res.writeHead(404, {

    'content-type': 'text/html;charset=utf8'

                });

    res.end('你访问的页面不存在');

            }

    res.writeHead(200, {

    'content-type': type

            });

    res.end(data);

        });

    });

    app.listen(9999);

    浏览器事件环

    浏览器事件环: 全局执行环境(执行上下文)

        js单线程(主线程)——程序的执行路径

        同步有限,然后异步。

        异步线程:放置缓冲区【异步任务队列】

            setTimeoutsetInterval              宏任务

            onclick:事件回调

            promise                             微任务

            ajax

        微任务 > 宏任务

        script宏任务先执行,之后的执行过程:先清空微任务,再执行宏任务。

    ==================================浏览器常用的宏任务微任务====================================

    宏任务:JS渲染,ui渲染,定时器:setTimeoutsetIntervalsetImmdiate ,node中的IO操作

    微任务:promise[不同版本实现,特例:宏任务],process.nextTick, Object.observe , MutationObserver

    Vue.nextTick(function(){}) ——异步的微任务

        支持promise,采用promise实现;

        不支持,使用MutationObserver

        不支持,使用setImmediate

        不支持,使用setTimeout




    待深入部分:

    模块化
    事件环

  • 相关阅读:
    @loj
    @loj
    @划水记@ THUWC2020 (?)
    @codeforces
    @loj
    Spark设计理念与基本架构
    Spark源码解析
    Spark Submitting Applications浅析
    Spark RDD基本概念与基本用法
    Storm基本原理概念及基本使用
  • 原文地址:https://www.cnblogs.com/macro-renzhansheng/p/13041549.html
Copyright © 2020-2023  润新知