Making Upload Friendly URL

I decided to setup an instance of WordPress as a dedicated site to host images. Similar to a CDN, this instance will only be responsible for hosting images. The benefit of this approach is that those images can be shared across multiple sites, independently of the application that creates the sites.

Users can have a “CDN” account, to upload images.

To make the referencing of those images simpler. I did the following changes:

  1. In WordPress > Settings > Media, I unchecked the option that list media assets in folder containing the date of upload. In that way, assets will be access directly from the upload folder (e.g.
  2. I added a new redirect rule to Apache, to redirect any URL that start with “{HTTP_HOST}/uploads/…” to “{HTTP_HOST}/wp/wp-content/uploads/…”. In that way referencing an asset in the CDN instance will be easier (e.g.

.htaccess rule

RewriteEngine On
RewriteCond %{REQUEST_URI} ^/uploads/(.+?)$	
RewriteRule ^(.*)$ http://%{HTTP_HOST}/wp/wp-content%{REQUEST_URI} [L]

The biggest benefit of this approach, is that we can user the WordPress admin interface to manage assets in the “CDN” instance.

Add Window Load Event Without jQuery

Let’s say that you would like to trigger you code after the page is done loading. Easy, just use jQuery to attach a listener to the ready event (e.g. $(function() { ….}); OR $(document).ready(function() {…}) ). But what if jQuery isn’t loaded yet? Well, here is something that you can try.


function callback() {
    /* your code here */

'attachEvent' in window && window.attachEvent('onload', callback, false);
'addEventListener' in window && window.addEventListener('load', callback, false);

Tracking Pixel Code

function getAllInfos(url) {
    url += "?ver=1";
    url += "&url=" + escape(location.href);
    url += "&ref=" + escape(document.referrer);
    url += "&ua=" + escape(navigator.userAgent);
    url += "&reso=" + escape(screen.width + "x" + screen.height);
    url += "&greu=" + escape(document.body.clientWidth + "x" + document.body.clientHeight);
    url += "&rand=" + escape(Math.random());
    return url;