[ 
https://issues.apache.org/jira/browse/COUCHDB-2489?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14236166#comment-14236166
 ] 

Ben Keen commented on COUCHDB-2489:
-----------------------------------

Okay, think I have an approach for this. It's not too bad! 

First, we'd update the generated index.html page to output the following:

{code}
<script src="libs-HASH.js"></script>
<script>require("main-HASH.js", function() { });</script>
{code}

libs-HASH.js would contain the following, in order:
- requireJS
- the requireJS config file (/app/config), minus the "deps" property so it 
doesn't auto-run our startup code
- the list of whatever libs we use: d3, jquery, lodash, backbone etc. Since 
we're wrapping them all in AMD format, we need require to have already been 
loaded, hence the order here.

I figure this file would be the same for dev + prod. We could either add a 
watcher to auto-generate the file, or just generate it when starting Fauxton.

main-HASH.js would just be our existing app/main.js file - no changes. The key 
difference is that in the Grunt process, we'd provide it with a list of 
dependencies to omit. These would be the libs specified in the previous file: 
d3, jquery etc. So the filesize will be significantly smaller, but all of those 
dependencies will have been loaded.

For dev, the filename would just be "main.js"; for prod it would be 
"main-HASH.js". This would be handled by Grunt, just like now.

That's all we need, I think.

Just to really emphasize the point to all this: by separating them into the two 
files like above, we'll have the much-smaller code that always changes be in a 
separate bundle, and the libs (larger, and which seldom change) in their own 
file. That'll greatly reduce the amount of stuff a user has to repeatedly 
download.

______________

N.B. once this is complete, it would be nice to update the server to send 
1-year cache headers on all CSS/JS files that end in '-' + 32 char hash + 
'.js'|'.css']. The hash ensures uniqueness of the contents, so we can safely 
increase the cache expiry times to prevent needless downloads/checks.


> Remove libs from main require.js bundle 
> ----------------------------------------
>
>                 Key: COUCHDB-2489
>                 URL: https://issues.apache.org/jira/browse/COUCHDB-2489
>             Project: CouchDB
>          Issue Type: Improvement
>      Security Level: public(Regular issues) 
>          Components: Fauxton
>            Reporter: Ben Keen
>            Assignee: Ben Keen
>
> This'll take a little investigation. Right now the prod bundling process 
> sticks everything - libs + code - into a single require.js file. Libs seldom 
> change; code changes all the time. Split them so that browsers would cache 
> the unchanging libs file and not force a re-download each time. The key libs 
> are: 
> - require
> - d3
> - jquery
> - backbone
> - bootstrap
> - lodash 



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to