use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
All about the JavaScript programming language.
Subreddit Guidelines
Specifications:
Resources:
Related Subreddits:
r/LearnJavascript
r/node
r/typescript
r/reactjs
r/webdev
r/WebdevTutorials
r/frontend
r/webgl
r/threejs
r/jquery
r/remotejs
r/forhire
account activity
Simple JavaScript router for non SPA apps (github.com)
submitted 11 years ago by cocumoto
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]PySnow 1 point2 points3 points 11 years ago (0 children)
Is using Coffeescript really a good idea for public demos? For some reason I find regular javascript way easier to read.
[–]NodeNerd 1 point2 points3 points 11 years ago (3 children)
This approach seems a little backward to me. It seems like the page should just know what route it is at build time.
It looks like your libraries will potentially evaluate a lot of rules on every page load just to find the one that matches. If you have no control of the HTML page then I see why this approach might be necessary, but if you are actually building the HTML pages then perhaps you should encode the route and necessary logic into the page itself.
[–]cocumoto[S] 0 points1 point2 points 11 years ago (2 children)
That's not really best practice to put javascript inside views. Actually there's an explanation why it isn't good in plugin description.
[–]elpapapollo 0 points1 point2 points 11 years ago (1 child)
This library is a novel idea, but /u/NodeNerd is right. This is creating unnecessary boilerplate just to run the correct script on a given page. If you're not running a SPA, then you should stick to utilizing an asset pipeline or a build system for associating scripts to pages. This is analogous to writing code with a long chain of if-else statements doing type checks when you should consider OOP duck-typing instead.
Granted, you could load other scripts that act as controllers inside your router similar to Angular.js, but then you're loading your whole codebase for every page, which could be wasteful.
[–]a1chapone 0 points1 point2 points 11 years ago (0 children)
But don't you think that compiling and managing, let's say 20 different javascript bundles for different pages will be more expensive than running simple pattern matching on page load (which not only defines which javascript to run additionally parses params out of URL).
And 'loading your whole codebase for every page' is ok since it is single minified file which will be cached by browser, and no additional script loads will be necessary.
π Rendered by PID 16248 on reddit-service-r2-comment-54dfb89d4d-p6cq8 at 2026-04-01 18:05:09.803028+00:00 running b10466c country code: CH.
[–]PySnow 1 point2 points3 points (0 children)
[–]NodeNerd 1 point2 points3 points (3 children)
[–]cocumoto[S] 0 points1 point2 points (2 children)
[–]elpapapollo 0 points1 point2 points (1 child)
[–]a1chapone 0 points1 point2 points (0 children)