CGI Room.nu

Programming, Scripting and Graphics

JavaScript minifier filter module for Roxen

28 June, 2010 by Jakob

Nowadays web sites and web applications tend to be more and more JavaScript driven which results in humongous JavaScript files. It’s not uncommon to have several 100 of bytes of JavaScript on a site. Of course web browsers cache stuff like JavaScript so that it only is requested from the server once. But judging from the visitor logs at work most people only visit our site once a month or so which means that cache will expire and all those scripts has to be requested upon the first visit.

Now, there are several ways to compact JavaScripts: Packer, YUI Compressor, Shrink Safe, jsmin and many more. Some of these just remove redundant white space and comments, some obfuscates the code and shortens variable and function names and what not. Many of these scripts and programs are very fine but they require you to manually minify your scripts, and that’s just a hassle!

But since we use Roxen CMS at work things get much easier if you write your own Roxen filter module which automatically minifies JavaScripts on the fly, given they meet certain criteria. And so I did!

I ported the original jsmin code written in C to Pike. Then it was just a matter of creating a simple filter module for Roxen. And then it was all done.

You can use two criteria to determine if a script should be minified or not:

  1. Path glob: In the module settings you can specify any number of directory globs or full paths. If a requested JavaScript either is in a directory matching a glob or is a direct match it will be minified.
  2. Query string variable: In the module settings you can define a variable name that if exists as a query string variable in the request the JavaScript will be minified. So:

    <script type="text/javascript" src="myscript.js?jsmin=1"></script>

    will minify myscript.js

And that’s that!

jsmin Roxen filter module 13:34, Mon 28 June 2010 :: 6.1 kB

Filed Under: Misc Tagged With: Javascript, Pike, Roxen

Blue Screen of Death

5 February, 2010 by Jakob

You don’t get surprised when you get to work one morning and your monitors looks like this, given your computer is running the bless from Redmond!

Man I wish I was running Linux at work as well!

(And no: I hardly drink any Coca Cola at all ;) )

Filed Under: Misc Tagged With: Rant

Gravatar module for Roxen

9 December, 2009 by Jakob

Although I’m working on some social web related Pike modules where a Gravatar module is included I needed a Gravatar module right now at work so I hacked up a standalone Gravatar Roxen module.

This is how it works

12 lines of RoXen Macro Language
  1. <ul>
  2. <emit source=“sql” host=“mydb”
  3. query=“SELECT name, email, `date`, body FROM my_comments”
  4. >
  5. <li>
  6. <gravatar-img email=“&_.email;” rating=“pg” size=“32”
  7. default-image=“/path/to/icon.png”
  8. /> &_.name; wrote at <date iso-time=“&_.date;” />
  9. <wash-html paragraphify=“”>&_.body;</wash-html>
  10. </li>
  11. </emit>
  12. </ul>

Download the Gravatar Roxen module 14:20, Wed 09 December 2009 :: 7 kB

Filed Under: Misc, Roxen Tagged With: Pike, Roxen, Share

A change of times

2 December, 2009 by Jakob

old Pripps ad

Times are changing! This old beer ad is in Swedish but in short it says:

Pripps in a new disposable pack, for the sailing tripp. Extra tip: Make a hole in the bottom of the empty pack and it will sink faster.

It feels we at least have come some way regarding recycling.

Click on the image for a full scale version.

Filed Under: Misc

Annoying WordPress thing…

18 October, 2009 by Jakob

It seems WordPress is hard coding the domain name into the database. How smart is that, or have I missed something? When I first set the site up on my local development server I soon noticed that various links were written hard with the domain and everything. Obviously that would f**k thing up once the site was moved to the public server. So I went into the settings and saw that there were two fields – WordPress address and Blog address – containing absolute paths. So I changed them to relative onces, e.g /blog instead of http://strindberg.loc/blog and things seemed to work properly.

Now I just realized that the guids in the RSS feed pointed to my development server. I looked in the database table and saw that there were hard coded references to http://strindberg.loc. So with a little UPDATE wp_posts SET guid = REPLACE(guid, 'strindberg.loc', 'www.poppa.se') I thought I had solved the problem. But then I realized some other guids in the RSS is generated on the fly, and they get f**ked up since the WordPress address now is relative and thus some guids looks like http:///some-url/. Is that good or what?

And try to figure out how to find out where those guids gets generated. My idea was to find where they are generated and there insert the HOST dynamically, but since there’s a zillion apply_filter(...) it’s virtually impossible to find where the shit gets generated (thanks to Netbeans it’s otherwise simple to follow the chain of execution. Just ctrl+click on a function call and the source of that function will be loaded.)

Ok, so now I have to put on my Sherlock hat and see if I can solve this. I find it hard to believe you shouldn’t be able to move a WordPress site from one domain to another without having to work your ass off!

If anyone have a solution – it’s perfectly possible I’m missing out on something here – I’m happy to know!

Filed Under: Misc Tagged With: MySQL, Netbeans, Wordpress

  • 1
  • 2
  • 3
  • …
  • 6
  • Next Page »

Categories

  • Action Script 3
  • Applications
  • Flash Animation
  • Linux
  • Misc
  • News
  • Programming
  • Roxen
  • Tutorials
  • User Science
  • Web Development
  • Xsl/Xslt
Copyright © 2021 CGI Room.nu