DEV Community


Posted on

Let's build: 'load to get faster early web development

When trying stuff out or doing early work on a web site or service it can seem slow and fragmented to restart your application server over and over again.

Instead of churning out all that Ctrl+C or D and possibly also restarting httpGate or nginx at every adjustment you could use a simple little trick that is suitable when testing app modules or just getting started on a project.


# libraries for the app server
(load "@lib/http.l" "@lib/xhtml.l" "@lib/form.l") 

(de work () 
    (load "app.l"))

(de go ()
    (server 8080 "!work"))

Once you have this you run and forget about it:

$ pil dev.l -go -wait

Now if you visit localhost:8080 it won't be spectacular.

Enter some GUI boilerplate into "app.l".


(app) # assuming you want session handling
    (html 0 "Test bed for savvy gravy" "@lib.css" NIL
        (<h1> NIL "It's alive!")))

Next visit will then look better, and as you work on and save "app.l" and reload localhost:8080 you'll see changes reflected immediately without restarting "main.l".


(setq *Awesome T)
    (html 0 "Test bed for savvy gravy" "@lib.css" NIL
        (if *Awesome
            (<h1> 'awesome "Apparently you're awesome!")
            (<h1> 'notsoawesome "Pretty sure you won't see this!") )))

Using this technique 'in production' isn't a good idea since file I/O performance is about as bad as it gets, but compared to restarting the same script over and over manually while allowing a separation of your development helper functions and globals in "dev.l" from the app code in "app.l" will feel like super powers.

There are of course other ways to achieve this or similar results, you could for example use coroutines or background tasks instead, laying ground for a more sophisticated integrated development and production administration environment. Or whatever it's called when you program your servers by pew-pew:ing messages at objects and watching web services grow out of it.

Next time we'll create a small guestbook application.

Stagling@Patreon for coffee donations, unless you'd perhaps, y'know, like to hire me or something, then I'm sure we could work something out.

Top comments (0)