CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
Changing Repetitive content

 



cekiert
Novice

Feb 23, 2011, 5:22 PM

Post #1 of 15 (2833 views)
Changing Repetitive content Can't Post

I was wondering maybe there is a existing code for this, maybe not. I am working on a site that may grow to several 100 pages quickly. I'm taking pride to keep my template small, unfortunately I'm currently using external js files currently 8 of them to be exact, for groups of items like a nav bar, social media, and copyright footer, ect is there a script that might be useful for this, i'm thinking in the html writing comments sectioning off areas, and have a server side script replace text within those comments in the html docs, any thoughts... I'd like to keep server load minimal, and ensure my pages are optimized for speed while loading.. the external js files would slow it down to much

maybe something like this...
example html file
<html>
<body>
<!--Form-->
form html
<!--End of Form-->
</body>
</html>

then be able to tell a perl script to replace the area between the two form comments with a list of files

<form name"blah">
<input="submit">
<form>

this might be what I have to do unless anyone has ideas on what might already be out there


(This post was edited by cekiert on Feb 23, 2011, 7:32 PM)


FishMonger
Veteran / Moderator

Feb 24, 2011, 5:27 AM

Post #2 of 15 (2823 views)
Re: [cekiert] Changing Repetitive content [In reply to] Can't Post

HTML::Template - Perl module to use HTML Templates from CGI scripts
http://search.cpan.org/~samtregar/HTML-Template-2.9/Template.pm

Template::Toolkit - Template Processing System
http://search.cpan.org/~abw/Template-Toolkit-2.22/lib/Template/Toolkit.pod

Mason - Powerful, high-performance templating for the web and beyond
http://search.cpan.org/~jswartz/Mason-2.01/lib/Mason.pm

Catalyst - The Elegant MVC Web Application Framework
http://search.cpan.org/~bobtfish/Catalyst-Runtime-5.80032/lib/Catalyst.pm


cekiert
Novice

Feb 24, 2011, 2:49 PM

Post #3 of 15 (2819 views)
Re: [FishMonger] Changing Repetitive content [In reply to] Can't Post

That was similar to what I was looking for but, it seems more cpu intensive for the server.. I wouldnt want to see it assemble a page for every request, i'd rather see it assemble and save once accessed from the admin area, I really didnt see that in the list... it was some good information, if nothing else turns up, i'll probably mod one of those thank you


FishMonger
Veteran / Moderator

Feb 24, 2011, 3:18 PM

Post #4 of 15 (2817 views)
Re: [cekiert] Changing Repetitive content [In reply to] Can't Post

How do you know it would be more cpu intensive than your own version of a templating system? How good of a Perl/cgi programmer are you?

Based on your original post, I can safely say that any one of the options I suggested (possibly combined with modperl or fastcgi) would be far superior than anything you can put together. They are ordered from easiest to use to the most powerful and all are designed to be very efficient.


(This post was edited by FishMonger on Feb 24, 2011, 3:23 PM)


leathan
Novice

Feb 24, 2011, 7:44 PM

Post #5 of 15 (2808 views)
Re: [FishMonger] Changing Repetitive content [In reply to] Can't Post

I might be udnerstanding you wrong, but if you want to just get some fast user input at dynamic times i would just use javascript directly in the file and add conditional statements...

But otherwise if you really want that html generated form useing perl I strongly recomend doing what Fish said, also depending on what hes doing it may be extremely server intensive but if it is extremely server intensive its most certainly because of a the raw amounts of requests, NOT BECAUSE running that actual perl code on your server is server intensive, that just means your programming things wrong.

In Reply To


cekiert
Novice

Feb 26, 2011, 4:07 PM

Post #6 of 15 (2798 views)
Re: [FishMonger] Changing Repetitive content [In reply to] Can't Post

sorry its been a few days
I've picked up perl a few times dozen times in a few years I use several other cgi, non cgi, and non web design languages too... as far as cpu intensity, The options I saw, perl will assemble the page with each page hit verse assembling once directly to one file..

I'm referring to using this in a massive site, specifically I want to keep the cpu resources low on the server I am aiming for using a shared server in order to keep cost down. basically if my site has say 100 people on it at peak time I dont want the server running 100 instances of the perl script, opening up around 8 files each every 30 seconds... I'm going look at those links again maybe I missed a script.. Thanks


cekiert
Novice

Feb 26, 2011, 4:14 PM

Post #7 of 15 (2797 views)
Re: [leathan] Changing Repetitive content [In reply to] Can't Post


In Reply To
I might be udnerstanding you wrong, but if you want to just get some fast user input at dynamic times i would just use javascript directly in the file and add conditional statements...

But otherwise if you really want that html generated form useing perl I strongly recomend doing what Fish said, also depending on what hes doing it may be extremely server intensive but if it is extremely server intensive its most certainly because of a the raw amounts of requests, NOT BECAUSE running that actual perl code on your server is server intensive, that just means your programming things wrong.

In Reply To


To keep a better Ceo score, having alot of external files slow the load time down lowering your score.
I'm considering this site getting 100-1000 people at a time peak... thats alot of perl code running on every minute...


cekiert
Novice

Feb 26, 2011, 4:51 PM

Post #8 of 15 (2795 views)
Re: [cekiert] Changing Repetitive content [In reply to] Can't Post

Thanks for your time guys.. I'm sure I can handle making it more efficient...
instead of apache going on every hit:
call perl to do this
open 8 files
look in the template file where to insert data from 7 other files(hardrive having a panic attack...increasing access time.. by a millisecond)
send generated data...

I'll do something like
after I do any updates ill run a update script:
call perl to do this
open 8 files
look in the template where to insert data 7 times
save generated data, then loop to every page
then I'd check it over for any mistakes in the html or whatever
then I would copy files over

then when I get a hit the server only needs to
send data from one already generated file

as for perl using to much cpu, some people maybe interested in
http://www.webmasterworld.com/forum13/1575.htm needless to say it can happen if you think the sky is the limit on shared hostingBlush


FishMonger
Veteran / Moderator

Feb 26, 2011, 5:29 PM

Post #9 of 15 (2793 views)
Re: [cekiert] Changing Repetitive content [In reply to] Can't Post

If that's the way you want to approach the issue then so be it, but it's not a very good approach.

The forum link you posted supporting your decision is not only old/outdated but the limited amount of Perl code suggested is really bad. I'd stay far away from those types of recommendations.


cekiert
Novice

Feb 26, 2011, 7:06 PM

Post #10 of 15 (2791 views)
Re: [FishMonger] Changing Repetitive content [In reply to] Can't Post

For whatever reason I'm only seeing better performance. As a embedded programmer I get accustom to working with limited resources.. I don't see what is wrong here, the code I'm working on now only needs to run once and doesn't even need to reside on the server. I can still edit small files to affect all pages, not as fast as the other way but fast enough, for the trade off of repetitive page building per hit, the performance left on the server can be used for other site requirements.. It seems that I'm hearing doubt on any server performance difference...


Zhris
Enthusiast

Feb 26, 2011, 8:29 PM

Post #11 of 15 (2784 views)
Re: [cekiert] Changing Repetitive content [In reply to] Can't Post

I understand that if webpages need to be dynamic i.e. display the latest info from a database each time the webpage loads, then using a Perl template module would most definately be the route to go, if Perl is your choice language.

If, from what I gather you are trying to do, content doesn't change unless the admin changes it, then yes it would be more efficient to "embed" content onto the webpage.

However, your proposed method seems unneccessary, when you could be using server side includes i.e. through PHP. A common example would be when including a generic header and footer. An example:


Code
<!-- home.php --> 
<?php include ("header.htm"); echo PHP_EOL; ?>
<div class="content">
<?php include ("content/home.htm"); echo PHP_EOL; ?>
</div>
<?php include ("footer.htm"); echo PHP_EOL; ?>


This way you can make changes directly to i.e. "home.htm", that will be immediately applied, with little sacrifice in performance each time the PHP script is run.

Chris


(This post was edited by Zhris on Feb 26, 2011, 8:44 PM)


cekiert
Novice

Feb 26, 2011, 11:02 PM

Post #12 of 15 (2769 views)
Re: [Zhris] Changing Repetitive content [In reply to] Can't Post

Yea I agree with that.. I just finished my little assembly script. and it will remove alot of pointless repetitive work I can still insert perl code in if a want, but the purpose was to eliminate a few 100 instances trying to read 8 files each and then assembling... now I dont need to look at one 40kb file and now after updating a js file I only need to run a perl script and it assembles everything to a folder ready to be uploaded


FishMonger
Veteran / Moderator

Feb 27, 2011, 7:47 AM

Post #13 of 15 (2752 views)
Re: [Zhris] Changing Repetitive content [In reply to] Can't Post

The PHP include approach you suggest could also just as easily be done in Perl.


Zhris
Enthusiast

Feb 27, 2011, 8:30 AM

Post #14 of 15 (2749 views)
Re: [FishMonger] Changing Repetitive content [In reply to] Can't Post

Your absolutely right. It could easily be done in Perl, and I should have provided a Perl example (afterall this is a Perl forum).

However, from experience, I would choose to use PHP for the above task as I feel its better suited for combining code (PHP) amoungst XHTML. But I guess that could be down to oppinion. When I build a website I usually use XHTML for front end looks, PHP to glue everything together, and Perl for key backend coding. It works very nicely, except it can get pretty complex when using sessions and post data. But this method allows me to create "widget" based templates, where I can put whatever I want where I want with minimum hassle.

Chris


(This post was edited by Zhris on Feb 27, 2011, 8:37 AM)


cekiert
Novice

Feb 28, 2011, 4:43 PM

Post #15 of 15 (2735 views)
Re: [Zhris] Changing Repetitive content [In reply to] Can't Post

I'd like to say, I honestly appreciate all the help, I'm happy with my end result.. Although my result was different then what was suggested.

My outcome is appearing to be working slightly better, for the test server's cpu efficiency. just going from eight files(7 external js with embedded html code) to one the more noticeable impact is the hard drive is running 20 degrees cooler, during long durations of stress testing

The suggestions above I'm sure are great at quick and easy site management.. but I don't think the end results would be as good for minimal hardware preformance..

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives