|
cjoki wrote: This style of code allows me to separate PHP and HTML from css and js.
How is $pg = "<html>\n"; separating the two? You include the HTML IN your PHP.
CSS and JS can be separated from HTML into several separate files (using the link tags and the script src attribute, respectively), rather than being scripted in, so to say. I prefer having separate files. When separating JS and CSS there are always certain bits which have to overlap such ass the class attributes. Smarty does the same for PHP and HTML.
This is a very basic example of using Smarty.
index.php
<?
include('Smarty.class.php');
$Smarty = new Smarty();
$Smarty->assign( 'message' , 'Smarty Rocks!!!' );
$Smarty->display( 'index.tpl' );
?>
index.tpl
<html>
<head>
<title>Smarty Example</title>
</head>
<body>
{$message}
</body>
</html>
cjoki wrote: Template engines just add another layer that IMHO is not needed and does little more than complicate a design and add to the learning.
After looking at the above code, you can't say that it's not insanely simple.
cjoki wrote: and why are you asking me to look into a template system when your concern is performance?
Quite simply, I don't actually do the website design (I'm colour blind), I just worry about the functionality. The designer I hire designs the site and then writes the HTML and CSS and leaves me to do all the JS and server side, without having to get in my way. So if he wants to redesign the site then he just changes the templates, rather than having to troll through my PHP code, the same could be said if I want to redo the back-end of the site.
Have a read of this[^].
If at first you don't succeed, you're not Chuck Norris.
|
|
|
|
|
I could have stated this better, but I meant php and html, then js, and then css are seperated and controlled by code logic.
I do entire projects, including layout and design, programing and db design. I have no need to separate the page further, than is needed by css and js, or even to keep the code more manageable.
Also if you know php you can easily maintain my code. There is no need to learn additional language rules required by a template engine.
My file structure is also way more simplistic than a template engine. I do not have to hunt a templates code to find where they buried a code fragment.
...and I counter your simple smarty code with an even simpler php code that only requires 1 file and will run..much...much faster!
<?php
$msg = "Smarty What...?";
echo "<html>";
echo "<head>";
echo " <title>PHP Example</title>";
echo "</head>";
echo "<body>";
echo "<h1>".$msg."</h1>";
echo "</body>";
echo "</html>";
?>
I sure we can go tit for tat, but this has gone way of topic from the original post. My reply was not meant to start a flame war, but to offer another option to the author.
|
|
|
|
|
I'm sorry, but I only echoed the variable, NOT the rest.
<?
$msg = 'Smarty is cool';
?>
<html>
<head>
<title>PHP Example</title>
</head>
<body>
<h1><? echo $msg; ?></h1>
<!-- OR -->
<h1><?=$msg?></h1>
<!-- If you have quick echoing enabled -->
</body>
</html>
No unnecessary processing wasted by unnecessary echoing, holding all the output in memory or wasted time compiling strings using " instead of '. Which is what I said in the first place.
Template engines generate it all for you, quite efficiently. They are only sluggish when compiling a template for the first time. I have to admit that it did take me a very long time (almost 5 years) to convert.
cjoki wrote: My file structure is also way more simplistic than a template engine. I do not have to hunt a templates code to find where they buried a code fragment.
Using the template engine doesn't make my file system any more complicated:
/
classes/
logs/
smarty/
templates/
templates_c/
htdocs/
css/
js/
img/
Enough of the flame war. I call a truce, apologies.
cjoki wrote: With echo once something is echoed its gone to the browser.
Have a look at Output Buffering[^]. It's quicker than both of our methods. I was going to talk about it when talking about the header redirection, but it's too advanced for what he is doing.
I'm thinking about writing a couple of articles (when I have time) about OOP in PHP. It'll be more appropriate to continue the discussion then.
If at first you don't succeed, you're not Chuck Norris.
|
|
|
|
|
I never write broken HTML, large projects to easily become a mess to read. And honestly I have never had an issue with performance. But I would be interested in your article when it is ready...
I am familiar with Output Buffering, but have not used it all that much, although maybe I should.
Currently I am updating my js knowledge to the current standards of code separation...(i.e.: removing things like ...to and js adding the event logic at the end page load.).
I am also contemplating an issue of external (multiple) css file loads vs style tags with css loaded based on page need using php code logic. I suspect in projects with a large number css rules can be refined to reduce the file size (sent to the browser) by send only the needed rules without the need for a larger number of file reads (split css files). But this flies in the face of separation of style from html...and I need to test, well I first need to figure out how I could test.
All the best
cjoki
modified on Monday, October 12, 2009 5:12 PM
|
|
|
|
|
cjoki wrote: Currently I am updating my js knowledge to the current standards of code separation...(i.e.: removing things like ...to and js adding the event logic at the end page load.).
You get a thumbs up That's the kind of thing I enjoy doing. Have a look at using jQuery. jQuery could do what you want with a single line.
$(document).ready(function() {
$('#btn').click(some_function);
}); (Added new lines to make it more readable.)
cjoki wrote: I am also contemplating an issue of external (multiple) css file loads vs style tags with css loaded based on page need using php code logic. I suspect in projects with a large number css rules can be refined to reduce the file size (sent to the browser) by send only the needed rules without the need for a larger number of file reads (split css files). But this flies in the face of separation of style from html...and I need to test, well I first need to figure out how I could test.
I was playing around with this the other day.
For performance, minimizing your js files, using a tool like this[^], greatly improves page load times. The same applies for css file. Loading multiple small css files is slower than loading one big css file. There is a css compressor[^] as well.
Note: It's only worth minimizing files on release versions.
A good tool for testing page load time is the Firebug addon[^] for Firefox. It has a tab called 'NET' which shows you how long everything takes to load. It also debugs JS which is very useful and shows the DOM while JS is changing it.
Hope that helps
If at first you don't succeed, you're not Chuck Norris.
|
|
|
|
|
yeah, I keep forgetting about firebug's Net tab for download times, I tend to use it when debugging ajax calls. I also found a tool from yahoo, called Y!Slow that is a firebug plug-in. I have yet to play with it much but it also shows performance slow downs and offers corrective tips.
On the css, my question comes down to 1) multiple css files, 2) one big css file or 3) adding css rules to a style tag in the page by way of code logic. Your reply confirms my gut feeling about a large number of small css files (is this true if the files are only added to the servers output on the fly and as needed?), but then there is the 1 large file vs the dynamic css rules in a style tag.
With 1 large file there is no control over the css output...that I can think of. But the flow goes; page is requested by browser and then the css is request after the page download completes.
The code added to the pages style tag, can use some simple logic rules to minimize the amount of css rules added to the page, thus making it small (vs the entire css file) and would not require a secondary file request for a separate css file (the 1 large css file).
It would seam logical that the dynamic css rules added to the page will be the better performance solution. Of course I am not including compressed css files which is another performance question.
JQuery, I have avoided...no real reason, but I have. I am still hand coding JavaScript.
|
|
|
|
|
The method I've used recently is to use one big css file. The browser normally caches it, so the only real performance loss will be the first page load.
I went through a phase of having a separate specific css file for every page, and a global one included on each page. It was annoying, to say the least, worse to maintain than templates. Plus each page had to cache a separate page which slowed the load time.
I tend to cache as many things as I can as it produces quicker load times and doesn't take up as much precious bandwidth
If at first you don't succeed, you're not Chuck Norris.
|
|
|
|
|
good point and well taken
|
|
|
|
|
Hi
Anybody here to guide me to dual boot windows and linux mint.
|
|
|
|
|
hi, any one tell me how to install the linux os to my pc
|
|
|
|
|
thangvel wrote: any one tell me how to install the linux os to my pc
From a Linux distribution DVD.
|
|
|
|
|
Insert a Debian Bootable Installation DVD in your drive and install it .
|
|
|
|
|
It is possible to download php code from any website without log in to web server ?
|
|
|
|
|
No, PHP is a processing language that outputs html, without access to the server (or knowledge of any backup php files) you cannot obtain the php source code after it's been processed.
|
|
|
|
|
the question is very basic and simple
but im not sure how to put it
basically i have an x amount of links on a page to open up in a newtab or window
and after ALL links are clicked, i want the main page, to auto redirect to somewhere else
so basically
on this page, www.unrealart.org/first.php
after all links are clicked on thats page, i want it to redirect to
www.unrealart.org/riders.php automatically
|
|
|
|
|
You'll need to code something using the javascript onclick event - but I would let the users change their page (perhaps display a continue button after all links are clicked). Reason being: what if they clicked the final link and it failed and so they go to click it again and it's gone.
|
|
|
|
|
I'm in a lecture and I'm bored. I wrote this quick little example which should do it for you.
It assigns a hreflang attribute to each link which has been clicked.
The code uses jQuery and is self explanatory.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>Example</title>
<script type="text/javascript" src="jquery-1.3.2.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$('#links').children('a').click(function() {
$(this).unbind('click').attr('hreflang','en');
checkAllClicked();
});
});
var allClicked = false;
function checkAllClicked()
{
allClicked = true;
$('#links').children('a').each(function()
{
if (typeof $(this).attr('hreflang') == 'undefined')
{
allClicked = false;
}
});
if (allClicked)
{
window.location = 'redirectedto.html';
}
}
</script>
</head>
<body>
<div id="links">
<a href="target.html" target="_blank" title="New Window">1</a>
<a href="target.html" target="_blank" title="New Window">2</a>
<a href="target.html" target="_blank" title="New Window">3</a>
<a href="target.html" target="_blank" title="New Window">4</a>
</div>
</body>
</html>
If at first you don't succeed, you're not Chuck Norris.
|
|
|
|
|
Is it possible to fetch stock data from nseindia Like "http://nseindia.com/marketinfo/equities/cmquote.jsp?key=BHARTIARTLEQN&symbol=BHARTIARTL&flag=0" using php. I was able do it before but not now after nseindia done some changes in its site.Is it still possible to get data ?
|
|
|
|
|
|
I used it before i ask this question but it is not doing what i want it is showing label but not showing price like "last price "
|
|
|
|
|
Hey, i was wondering where i can find some decent python tutorials that i can download in the PDF format???
Your help will be greatly appreciated.
Todd.
|
|
|
|
|
Greetings:
Although you'll end up getting all of the Python documentation, including the language reference and C API, the tutorials over at Python's official site, python.org are still some of the best around: http://docs.python.org/download.html[^]
For practical applications and uses for Python, Mark Pilgrim's Dive Into Python is also a tremendous resource: http://diveintopython.org/#download[^]
I hope this was of help....
|
|
|
|
|
|
Hi
I am trying to building a site where people can post there thoughts such as twiter, face book etc.
Second, Could some one advise me when anybody fill a form online and click submit. It goes to database but I am wondering where is data base. I mean in my personal storage or where I will register my website. Can retive that data .
Finally, Could some advise me how back end process works such as once i build site, how to trasfer files , How professional web sites works as I have no idea about it .
Thanks
|
|
|
|
|