Вырезаем SSR и ускоряем Хабр в 10 раз

, … . - -. , , , . - , . , SSR .



, , : - . , !







, , , 2500 . , , 1400 . , , . . . :



(HTML) (JSON) (JSON)
12 MB 3.4 MB 3.4 MB
1000 KB 700 KB 700 KB
45 s 42 s 5 s
5 s 42 s 5 s
DOM 116K 100K < 1K
700 ms 30 ms
1800 ms 30 ms
800 MB 1000 MB 80 MB






  • — HTML JSON . , " ". , .
  • — , .
  • — (, — ), F5 ( " ") . .
  • — , , , , .
  • DOM document.getElementsByTagName('*').length , .
  • — . .
  • — . .
  • — , (shift+esc) .


. - — .







: . HTML. : HTML, "" JSON VueJS . , HTML. HTML , , .



, JSON 4 HTML. Tree , , JSON . , , , — 30%.



HTML , :



  1. , 8 , . loading="lazy", .
  2. HTML , , . DOM, HTML . — HTML.


, DOM . , . VueJS , .



100K DOM . 40 . .



DOM . , , , 700. , . — 2 . DOM . DevTools , .







— DOM . , . :



. . , , .
, . ### , . , .
. ### . ## . ###
. ## . ## . ### . # . ##
### ### ## ### ## ## ### ## #


:



  1. .
  2. , .






$mol, , , $mol .



JSON. , , , . $mol_data:



const Person = Rec({
    alias: Str,
    id: Str,
    login: Str,
    fullname: Maybe( Str ),
    avatarUrl: Maybe( Str ),
    speciality: Maybe( Str ),
})

const Comment =  Rec({
    id: Int,
    author: Maybe( Person ),
    children: List( Int ),
    isAuthor: Maybe( Bool ),
    isPostAuthor: Maybe( Bool ),
    message: Str,
    parentId: Int,
    score: Maybe( Int ),
    timeChanged: Maybe( Moment ),
    timePublished: Maybe( Moment ),
})

const Comments_response = Rec({
    comments: Dict( Comment ),
    threads: List( Int ),
})


null , .



, . , :



@ $mol_mem
comments_data() {
    const uri = `https://m.habr.com/kek/v2/articles/${ this.article_id() }/comments/`
    const data = Comments_response( this.$.$mol_fetch.json( uri ) )
    return data
}


, , . , HTML. $mol_html_view:



<= Article $mol_html_view
    html <= article_content \
    highlight <= search
    image_uri!node <= image_uri!node \


( view.tree, , .)



HTML, $mol_view , . , $mol_html_view , .



image_uri, IMG , . , src , data-src. :



image_uri( node : HTMLImageElement ) {
    return node.dataset.src || node.src || 'about:blank'
}


. / .



@ $mol_mem_key
comments_visible( id : number ) : readonly number[] {

    if( this.comment_expanded( id ) ) {
        return this.comments_all( id )
    } else {
        return this.comments_filtered( id )
    }

}


, . , $mol . , , - — .



, , , , . . — . :





Ctrl+F , $mol_hotkey :



plugins /
    <= Search_key $mol_hotkey
        mod_ctrl true
        key * F?event <=> search_focus?event null
    <= Theme $mol_theme_auto


:



search_focus( event : Event ) {
    this.Search().Suggest().Filter().focused( true )
    event.preventDefault()
}


, $mol_theme_auto, .



, , $mol_lights_toggle:



tools /
    <= Lights $mol_lights_toggle
    <= Sources $mol_link_source
        uri \https://github.com/nin-jin/habrcomment
    <= Search $mol_search
        query?val <=> search?val \


, .



, , $mol_style, , :



$mol_style_define( $my_habrcomment , {

    Orig: {
        flex: {
            grow: 1,
            shrink: 0,
            basis: per(50),
        },
    },

    Article: {
        maxWidth: rem(60),
    },

    Comments: {
        flex: {
            shrink: 0,
            grow: 1,
        },
    },

    Comments_empty: {
        padding: rem(1.5),
    },

} )


:



include \/mol/offline/install


Service Worker, .



, , , .



, : https://nin-jin.github.io/habrcomment/#article=423889



, :



javascript: document.location = document.location.href.replace( /\D+/ , 'https://nin-jin.github.io/habrcomment/#article=' )






400 , . :



  • /
  • /
  • /


5 . 6 ( 2 , ). , . .



. , HTML . , - , :



<= Message $mol_html_view
    minimal_height 60
    highlight <= search \
    html <= message \
    image_uri!node <= image_uri!node \


HTML . , , , .



5 . 10 .



API, — , , . . , — . :



@ $mol_mem
comments_data() {
    const search = encodeURIComponent( this.search() )
    const uri = `https://m.habr.com/kek/v2/articles/${ this.article_id() }/comments/?search=${search}`
    const data = Comments_response( this.$.$mol_fetch.json( uri ) )
    return data
}


, , . . , . - — . API. — .



, — , HTML, , - : , , , BR, . , - , - .



$mol_html_view HTML- — , . , , .



, :



  1. — - $mol_list. , . - .
  2. , overflow-anchor, , . , , , 100K , .


— , . , , . , , .







  1. SSR PWA.
  2. , , .
  3. , — .
  4. VueJS — , $mol — .
  5. , .
  6. , .






  1. — , .
  2. $mol — .
  3. $mol MAM — , , .
  4. $mol — - -.



All Articles