473,394 Members | 1,828 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

building a set of defined constants for application paths

Okay, I've come up with hacky workarounds every time I build an app, and
now I just need some tips on how to do this correctly and efficiently.

I usually have a head.inc and/or a constants.inc with definitions like
(SITE_ROOT,$_SERVER['SERVER_NAME']."/myApp);
(VERSION,"0.6.2");
(APP_ROOT, SITE_ROOT."/".VERSION);
(SMARTY_DIR, APP_ROOT . "/smarty");
(ADMIN_DIR, APP_ROOT . "/admin");

I'm sure you get the idea, and I bet you have them too. Some of these go
fine, but many of them are all screwed up, esp. any dealing with
-CSS (the stylesheets never seem to get included until my fourth attempt
at writing the URL)
-javascript (same)
-images (sometimes ... it seems like different servers treat the initial
slash in src="/thingy.png" differently?)

Anyway, I always run into these snags in the midst of some project, and
I figure out a hacky thing to just make it work. Now I want to get
input/tutorial links, etc. on how to do this right:

-do src= (script and img), action= (in a form), and href= (in a normal
"<a" link, and in a <link stylesheet) have different behaviors, or am I
imagining that?
-should I just build absolute paths for everything?

All advice greatly appreciated. If there isn't a single, definitive
tutorial, I might build one based on feedback here.

Thanks.
Sep 9 '05 #1
2 1258
Matthew Crouch said the following on 09/09/2005 14:48:
Okay, I've come up with hacky workarounds every time I build an app, and
now I just need some tips on how to do this correctly and efficiently.

I usually have a head.inc and/or a constants.inc with definitions like
(SITE_ROOT,$_SERVER['SERVER_NAME']."/myApp);
(VERSION,"0.6.2");
(APP_ROOT, SITE_ROOT."/".VERSION);
(SMARTY_DIR, APP_ROOT . "/smarty");
(ADMIN_DIR, APP_ROOT . "/admin");

I'm sure you get the idea, and I bet you have them too. Some of these go
fine, but many of them are all screwed up, esp. any dealing with
-CSS (the stylesheets never seem to get included until my fourth attempt
at writing the URL)
-javascript (same)
-images (sometimes ... it seems like different servers treat the initial
slash in src="/thingy.png" differently?)
Assuming you're talking about URLs in the HTML, then the server will
never see something of the form "/thingy.png". Your browser sees it and
converts it to an absolute URL before sending a request to the server.

The basic rules:

* Anything starting "http://" et al. is an absolute URL.

* An initial slash in a relative URL means "work from the domain root",
i.e. "/thingy.png" translates to "http://example.com/thingy.png",
regardless of what the current path is.

* Anything else is treated as relative to the path of the *current* page
as seen by the browser.

* "./" means "use the parent folder", so if you're at
http://example.com/foo/bar/index.html, then "./thingy.png", translates
to "http://example.com/foo/thingy.png".

This is described formally in RFC 1808.

Anyway, I always run into these snags in the midst of some project, and
I figure out a hacky thing to just make it work. Now I want to get
input/tutorial links, etc. on how to do this right:

-do src= (script and img), action= (in a form), and href= (in a normal
"<a" link, and in a <link stylesheet) have different behaviors, or am I
imagining that?
No, they should all behave the same.

-should I just build absolute paths for everything?


I would recommend not. It takes up more bandwidth to send (i.e. the HTML
file is bigger), makes the HTML harder to read (for humans, that is!),
and if you ever change domain or the root folder, then you'll have to
change all your links (unless you build the links dynamically).
--
Oli
Sep 9 '05 #2
Matthew Crouch wrote:
If there isn't a single, definitive tutorial,


Tutorial it is not, but RFC3986 (sec. 5) is the authoritative source
for relative-ref resolution.

http://www.ietf.org/rfc/rfc3986

--
Jock
Sep 9 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Mike Maxwell | last post by:
First, apologies if this is not the appropriate newsgroup (and let me know what would be a better group). I downloaded the Python 2.3.3, did the ./configure and make routine. 'configure' seems...
60
by: Sandeep Sharma | last post by:
Right from the time the first edition of K&R was released, the advantages of using symbolic constants, as opposed to "magic numbers", has been emphasized ---- and for good reason. I don't dispute...
11
by: Bill Nguyen | last post by:
I need to make a set of constants to be available for the whole application. Public const is confined to the form from which constants are declared. Is there a way to declare once and all forms can...
1
by: NachosRancheros | last post by:
Ok so I just started to program with Python about a week ago and I am trying to make a program that will take the path of a file and a shortcut command and save it to a text file. Eventually I want...
6
by: PC | last post by:
Gentlesofts, Forgive me. I'm an abject newbie in your world, using VB 2005 with the dot-Net wonderfulness. So, I'm writing a wonderful class or two to interface with a solemnly ancient...
14
by: adam.timberlake | last post by:
This is a really basic question for all you people out there who know PHP. This is not a problem but just something I'm confused about. I was reading the article below and wondered why are normal...
1
by: Noah | last post by:
I'm trying to match against Event.type for KeyPress and ButtonPress. Currently I'm using integer constants (2 and 4). Are these constants defined anywhere? The docs talk about KeyPress and...
8
by: =?Utf-8?B?ZG1idXNv?= | last post by:
I'm migrating a VB.NET 2003 application to VB.NET 2008. The 2003 app used the June 2005 Enterprise Library while I'm going to use the latest EntLib, 4.0 - May 2008. I copied the 2003 app to a...
7
Curtis Rutland
by: Curtis Rutland | last post by:
Building A Silverlight (2.0) Multi-File Uploader All source code is C#. VB.NET source is coming soon. Note: This project requires Visual Studio 2008 SP1 or Visual Web Developer 2008 SP1 and...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.