开发者

Best Way To "Drop In" Dynamic Content Into an Existing Static Site

开发者 https://www.devze.com 2023-02-17 17:47 出处:网络
A friend of mine has a static web site. She would like to add a registration form that would allow people to reg开发者_高级运维ister for classes. Re-creating the web site using ROR or Wordpress or som

A friend of mine has a static web site. She would like to add a registration form that would allow people to reg开发者_高级运维ister for classes. Re-creating the web site using ROR or Wordpress or something like is not in scope. We also want the user to use the same domain, regardless of whether he or she is viewing a static or dynamic page.

The least intrusive way that I can think of doing this with CGI, preferably using Ruby. However, I really don't like writing CGI code and I am much more comfortable with frameworks such as Sinatra and ROR.

Is using an advanced framework really even possible for this type of situation? If so, then is it more trouble than it's worth?

Thanks in advance!


If I were you I would do it in Sinatra, and perhaps use a front end like Nginx to redirect to your Sinatra app. So something like:

  location /myform{
    proxy_pass myserver:6000;
  }

Where your Sinatra is running on port 6000. Sinatra is very simple and you can probably do this in a short time. ROR I think is a bit heavy for this. We do things like this all the time for special needs/shared apps, even when they are already dynamic.


You can develop an app that injects the dynamic code into her static site via Javascript. I do that for one of my projects here at work and it seems to be an acceptable solution.

A quick HTML sample:

<!doctype html> 
<html> 
<head> 
<title>Test</title> 
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script> 
<script type="text/javascript" src="loader.js"></script> 
</head> 
<body> 
<div id="customcontent" class="contentlib"></div> 
</body> 

loader.js:

$().ready(function () {
    $('<style type="text/css"> ... </style>').appendTo('head');
    $('.contentlib').each(function() {
        $.getScript($(this).attr('id')+'.js');
    });
});

customcontent.js:

$().ready(function () {
    $('#customcontent').html(' ... ');
});

This is a bit more complicated than it has to be (the second script load based on the div's id) since I have to support multiple replacement on the same page.

Anyway, I could see you using this to inject your app from a 3rd-party website and, as long as you stuck to using AJAX form submissions, the average user would be none the wiser.

0

精彩评论

暂无评论...
验证码 换一张
取 消