Skip to content

Instantly share code, notes, and snippets.

@javajosh
Last active July 5, 2020 02:33
Show Gist options
  • Save javajosh/a2c1542277fa0fb64ce0c3fb225749bc to your computer and use it in GitHub Desktop.
Save javajosh/a2c1542277fa0fb64ce0c3fb225749bc to your computer and use it in GitHub Desktop.
A lightweight way to make same-site resources coherent without using templates or a front-end build

What if each webpage in a hierarchy loaded every specially named javascript file in every directory up to root? This would be a relatively lightweight way to impose what I think of as "proximity coherence" on a collection of resources. That is, each resource would not just be loaded as is, but rather load up whatever its ancestors wanted to add, such as a navigation or site identification. It is neatly recursive, too and would nicely support deep eneterprise-style hierarchies of content, including giving each level a chance to modify the behavior that preceded it. Meaning the root script, executing last, having the last word, so to speak, would be the most powerful. I've never seen this done, but it would be simple to do in JavaScript.

Probably the hardest part of the code would be breaking up the URL path into an array of subdirectories, which for a prototype could be as simple as const dirs = location.path.split('/'); while(dirs.length) include(dirs.pop(), 'index.js')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment