Absolute or Relative URL issues and the solution


This article demonstrates the issues occur due to the usage of relative URLs while shifting pages from one location to another or the misuse of relative URLs and how to overcome those issues.

Relative URLs examples:
/* HTML example */
<img src="image.jpg" />


/* CSS example */
.image-div
{
    background-image: url(image.jpg);
}

/* JavaScript example */
image.src = 'image.jpg';

Relative URLs and expected issues
In simple words, relative URL reference link on the same server (or domain).
  • <img src="image.jpg" /> Reference of a resource from same directory

  • <img src="../../image.jpg" /> In CSS/HTML, ../ used to reference parent directory. In the above example, ../ is used two times; so it is referencing a resource from 2-level parent directory.

  • <img src="sub-directory/image.jpg" />
    Reference of a resource from sub directory
The issue occurs when when shifting a page from one location to another which cause broken links.

/ and ../ are two different things:
  • <img src="/image.jpg" />
    Reference of a resource from root directory
  • <img src="../image.jpg" />
    Reference of a resource from 1-level parent directory

  • <img src="image.jpg" />
    Reference of a resource from same directory
Absolute URLs: The solution or ...
Absolute URLs solves most of relative URLs issues and also helps prioritized your website (SEO!). Absolute URLs also help testers or late-viewers to understand (+access) the located resource easily.

In JavaScript, we can create a global variable to store domain (root) URL:

/* Global variable */
var domainName = location.protocol + '//' + location.host;

/* Usage */
image.src = domainName + '/image.jpg';

JAMES PADOLSEY way of getting a fully qualified (absolute) URL in JavaScript:

function qualifyURL(url) {
    var img = document.createElement('img');
    img.src = url; // set string url
    url = img.src; // get qualified/absolute url
    img.src = null; // no server request
    return url;
}
// Tested successfully in IE6/7, FF2/3, Safari3, Opera9, Chrome (All on Windows XP) 

// EXAMPLE:
var myRelativeURL = 'blah/page.html';
alert( qualifyURL(myRelativeURL) );

Absolute URLs are helpful when shifting a page from one location to another because you don't have to change resource's URLs from within the shifted page.

A good link for parsing or making absolute URLs in JavaScript: https://gist.github.com/1088850

Protocol Level URLS:
<script src="//www.google.com/js/gweb/analytics/autotrack.js"></script>
<img src="//domain/image.jpg" />
Omitting the protocol—which makes the URL relative—prevents mixed content issues and results in minor file size savings.

What is Curvature?




What is the Curvature?
Curvature is a designer for curving. It generates Canvas 2d APIs relevant code in different forms.

Top Features
Curvature allows you:
  • Curves alignment (in any shape, in any portion of the page, to any point!) 
  • Drag whole drawing (all curves at a time!) 
  • Drag a single curve (all points at a time) 
  • Copy whole drawing and dragging-ability! Generates code in 4 forms: 1) relative coordinates 2) shortened relative coordinates 3) absolute coordinates 4) shortened absolute coordinates
Other common features
  • Undo support (for unlimited curves; whether millions of curves!) 
  • Starting and ending points replacement for a Bezier curve (sometimes: useful) 
  • Auto creates new curves (on mouse movement – on demand!) 
  • Fill color (in the last curve – clarifies the curve!)

New version of Curvature allows you hide/show the coding area so you can have a full drawing surface now!

Source code (Github!)
Source code of Curvature available at Github! https://github.com/muaz-khan/Curvature



What is "Shorten the code"?
This feature shortens the lines of auto generated code! Also it reduces size of the page!

Explain "Make relevant startingX/startingY points"
This feature was included in the first release of the Curvature. It generates relevant code from two points: startingX and startingY.

This feature allows you use e.pageX/e.pageY on these two points so you can easily drag/move whole shape (all curves at a time) without any disturbance.

Is it useful: "Replace starting and ending points' positions at new curve"?
Sure, in the complex shapes – I used it often.

"Auto create new curves" – what is this?
To auto create new curves at mouse movement. You don't have to click "New Curve" button or press "N" key to create new curve(s).

"Temporarily fill a color in the last curve" – isn't it a redundant feature?
For redundancy: it can be a redundant feature. However I included it for those who want to clarify the last curve!

"Drag whole curve/drawing" – Explain
  • "Drag whole curve" feature drags last curve as it is without any disturbance in the real shape of the "last" curve. 
  • "Drag whole drawing" drags whole drawing (at x-y coordinates) without any disturbance in the real shape(s).
Both are most useful features in the Curvature!

"Copy current drawing (all curves)" – isn't it limited?
This feature copies whole drawing and allows you drag "copied drawing". It is limited because it allows only one "paste" for copied drawing. Upcoming version of Curvature may support it fully – till that; use it carefully!

Curves alignment – digging into it



Curvature allows you align curves in two styles:
  • "Align Vertically":- Aligns y-coordinates of all (or selected) points. 
  • "Align Horizontally" (default selected):- Aligns x-coordinates of all (or selected) points.

"Align to relevant topmost points" (default selected) – aligns points with topmost (or first drawn) curve's relevant points.

You can set custom points too for alignment.

Test the tool: https://canvature.appspot.com/