youtube / spfjs

A lightweight JS framework for fast navigation and page updates from YouTube
https://youtube.github.io/spfjs/
MIT License
2.24k stars 147 forks source link

Allow first server response (which is a "normal" HTML response, not a SPF JSON response) to return CSS & JS aggregates #425

Open wimleers opened 8 years ago

wimleers commented 8 years ago

This would allow for better front-end performance. The first response (HTML) would then include aggregates. SPF responses would not include aggregates. Fewer requests for the first page load.

Necessary for this to work: ability of the name attribute to accept multiple values.

Example

Today, if the first page needs 3 JS files, and the second page needs 2 (of which one already exists on the first), that means 3 requests on the first page, 1 on the second. Wouldn't it be much better if those 3 requests (really, N requests) could be 1 request?

In other words, this would allow:

frontpage.html

<head><title>Frontpage</title></head>
<script name="a.js b.js c.js" src="aggregate.js</script>
secondpage.spf.json

{
  title: 'secondpage',
  body: {
    some_id: '<p>Hello world!</p><script name="b.js" src="b.js</script><script name="d.js" src="d.js</script>'
  }
}

Rather than requiring:

frontpage.html

<head><title>Frontpage</title></head>
<script name="a.js" src="a.js</script>
<script name="b.js" src="b.js</script>
<script name="c.js" src="c.js</script>

Existing logic

Test coverage should be added at https://github.com/youtube/spfjs/blob/cf4b0f499f174052003bce1a86ccb388a54cdbe1/src/client/nav/response_test.js — which also happens to show that this is not supported today.

RoneyThomas commented 7 years ago

Have you looked into webpack??? It can bundle all your JS dependencies???