Laravel and JQuery: Don’t Abuse GET

jQuery and Laravel are amazing libraries and frameworks but they don’t always inspire the best practices. Recently when building a basic app I made a fairly amateurish error without even realizing it at first. In building a simple Create/Edit route I used the Route::resource as a shortcut and for making AJAX requests to the route I used $.ajax() on page. The requests work great and everything seems to working fine until sending a large request and right then I realize $.ajax() is using a GET request rather than POST. There are a couple lessons here, you should have XHR requests properly outputting to console.log() so you see what your AJAX requests are doing. But more than that don’t expect jQuery and Laravel to do all the lifting through their syntactic shortcuts. At times, being more verbose with your code can avoid some nasty mistakes.

Explaining your Resource route with a couple ::get or ::post routes looks messy but actually can help to both avoid errors and aid in development by being more obvious to understand quickly.

As well, $.ajax() in jQuery is an all purpose request and specifying your Type can save headaches and keep requests from falling into the wrong lane.

Write in the moment, don’t trust your backlog

Committed bloggers post once a day, at least, where causal blog posters have sporadic posts over various lengths of time but strategic bloggers have a post ready every Tuesday at 1pm, or whatever they have scheduled. I am firmly in the second camp. Ever since I hiked in Japan, I have struggled to post, or even tweet, on a regular basis even though I write every day every hour. The worst part is I have dozens of posts ready to go, in my backlog.

Somehow I’ve managed to write a considerable amount of content that will never been seen. I’ll have an idea, write it out and then say, “Perfect I’ll send this out tomorrow.” Procrastination doesn’t come easy to me, otherwise my web clients would not be as happy as they are but for blogging, or drawing, there’s a problem. I’m the client. This is a common story, harsh self evaluation prevents movement, but with small ideas like blog posting there’s a unique twist.

Procrastinating on a novel or a movie is easy. You can easily talk yourself out of a huge undertaking and still avoid having to release. with something as small as a blog post the “it’s not done” is so much sharper because it is done. It might even be scheduled but rather than release we end up doing a little edit here, pushing back, maybe this post isn’t good to release now, there’s a new idea I should explore… The twist with smaller work is the procrastination comes at the end, rather than the beginning.

Though the procrastination might come at the beginning or end the lesson is the same. Don’t count on a plan or even what you’ve built already. Publish the post, send the email, take action and watch the small steps build into the bigger journey.

Stack jQuery events on elements to avoid delays.

While building a bit of code for phlodl.com jQuery was acting up when adding a simple mouseover to expand and the event was delayed when the mouse entered the element. To fix this I daisy-chained the events on the element to fix the delays:

Delayed animation:

$('.feature').mouseenter( function() {
$(this).animate({
height: 540
}, 'fast', function() {});
});

$('.feature').mouseleave( function() {
$(this).animate({
height: 300
}, 'fast', function() {});
});

Seamless:

$('.feature').mouseenter( function() {
$(this).animate({
height: 540
}, 'fast', function() {});
}).mouseleave( function() {
$(this).animate({
height: 300
}, 'fast', function() {});
});

Hourly noting, really?

Over the past 2 years I’ve become obsessed with noting, every hour of every day. Why? The original reason was meditative. I was trying to see my thoughts and track them from day-to-day. That idea failed pretty badly since words are terrible at communicating thoughts, well my thoughts anyway. What has succeeded though is looking back at how time is spent and understanding if my ideas and plans take place as conceive of. Continue reading Hourly noting, really?