If you want to serve a static equivalent of your site, you might want to consider transforming the underlying content by serving a replacement which is truly static. One example would be to generate files for all the paths and make them accessible somewhere on your site.
What they mean exactly? And how to do it?
Your question: What do they mean exactly?
If you want to serve a static equivalent of your site - static refers to html pages that are not dynamically created.
you might want to consider transforming the underlying content by serving a replacement which is truly static. Have 'hard copies' of your pages with the different alternatives
One example would be to generate files for all the paths and make them accessible somewhere on your site. Go through your site and create static html pages (or pdf's) of each one and store them in the file structure that is represented by the URL.
Example of the last:
http://site.tld/product/pear which today is a dynamic (created on the fly by the code and database) but is not really in an actual folder on the server called product. They are suggesting to create a copy of the dynamically created page and store it in an actual folder on the server called product with the name pear.
Your question And how to do it?
Will that work - sort of if you wanted to by adding a .html to the physical file (copy of the dynamic one) and save it but I suspect you will run into all sorts of difficulties that you will need to overcome with the redirect code in places like .htaccess. Another option may be change the domain part of the URL to include static ie http://static.site.tld/ for the static copies and the original URL as is for the dynamic version.
The other big challenge then becomes maintaining the two copies because the concept they talk about is for the content (what is shown in the browser) to remain static over time. Kind of breaks the whole concept of how we build dynamic web sites today e.g. online shops etc.
For example if it's a shop, I would use PHP to also create the physical file when a product is added and not include parts that are going to change, rather include a link to the dynamic info something like:
<?php
$file = 'product/pear.html';
// mysql code here to extract the info and format ready for writing
$content = "<html><head><title>$title_from_db</title></head><body>$page_content_from_db</body></html>";
// Write the contents to the file
file_put_contents($file, $content);
?>
Related
Say you have a css files loader style.php:
<?php
header('Content-type: text/css');
foreach(array('style1.css', 'style2.css', 'style3.css') as $f)
echo file_get_contents($f)
?>
Style1.css has 12KB, style2.css is 400kgs, and in the red corner obese style3.css weighting 800LBs is world champion at static resource bandwidth consumption!
I'm using style.php to combine the three files and send them to the client. I'm also using similar php files to send out JS resources, combined.
Is there some htaccess rule that I can tell to combine several static resources into a big one, and send that on-the-fly?
/EDIT:
This type of job CAN be handled by htaccess I'm sure I've read somewhere about server files included or something like that but I don't remember where. And I've also seen free hosting services that put a custom header or banner regardless of what files you host there.
Well this type of job (combining css files) cannot be handled by .htaccess. You can at best use mod_deflate to compress the css file's contents.
However in PHP code you can combine and compress various CSS files. Take a look at third method in http://www.catswhocode.com/blog/3-ways-to-compress-css-files-using-php
Finally take a look at minify here: http://www.minifycss.com/minify-tools/minify-css-tools.php
Eventually found what I was looking for. The thing was called Server-Side Includes (SSI).
I have a directory structure with files under directory 'web', which represents a white-label web site (html files, images, js etc.).
I also have some twenty different 'brands' let's call them 'web-1', 'web-2' etc. each containing specific files that should override the files in 'web' for a specific brand.
Apache is configured to find the files for each virtual site i in document root 'website-i'.
In order for each 'website-i' to contain content like 'web' with the overrides for brand 'web-i', my build script first copies all of 'web' to 'website-i' and then overrides it with the source files from 'web-i'.
There several problems with this approach:
It takes time to copy the files.
It takes a lot of disk space
Adding a new brand requires adding to the script.
Is there a best practice for doing this in a way that does not require duplicating files?
(with Apache and Linux)
Well, the best solution is with pretty simple server-side code but I'm going to assume you've already rejected that, maybe because you haven't permission to run code on the server (although if your hacking the config then you probably do).
A solution just in config could be to make it serve from the default root but rewrite the url if the file exists in the proper dir ...
RewriteCond /web-1/a_file -f
RewriteRule ^(.*)$ /web/$1
But you'd have to do this for every file in every brand. You might be able to be more clever about it if the files are stored in a dir that's the same as the hostname but that's getting too complex for me.
Seriously, server-side code is the way to go on this...
Strangely enough, a work colleague was in pretty much exactly the same situation a couple of weeks ago and he eventually rewrote it as PHP. Each site is a row in a database, one page which pulls out the changed text and urls for images, etc. and falls back to a default if there's nothing there.
Having said all that. Using links, as you say above, solves problem 2, probably much of 1 and I don't think there's a way around 3 any way.
I have an existing site in a path, and I've pointed the DreamWeaver site to it.
Under \templates there is a master.dwt file. But whenever I save this file, none of the html files which should make use of it change. What do I need to do to get DW to update the html files that make use of it? And how does DW know which files should be updated based on the template changing? Does it use an internal store or something because every time I copy the site to another machine, I'll need to link up all the pages to the relevant templates again.
I've tried going into Modify | Templates | Apply, but no templates are listed. I have a .dwt file in the path so why isn't it picking it up??
There's several possible issues in play here:
For Dreamweaver to properly recognize the existence of the template, the folder in the root of the site should be Templates and not templates.
Once Dreamweaver "sees" the Template properly you then need to make sure that the proper code is present in the child HTML files so Dreamweaver knows which files to update via the template. This code takes the form of HTML comments scattered throughout the page. You will always have the following line after the <html> tag:
<!-- InstanceBegin template="/Templates/TemplateName.dwt" codeOutsideHTMLIsLocked="false" -->
After that, editable regions are delineated with code that will look like this:
<!-- InstanceBeginEditable name="someregion" -->
stuff you can edit
<!-- InstanceEndEditable -->
Without the above, the child pages will not respond to the template.
Now for the real bad news. Unless the existing pages match up with the template exactly, you are going to have all kinds of problems getting the template to play nicely with the existing content. Doing Modify | Template | Apply Template to the page when the page is already fully formed will generate a dialog box that asks you map the content to the editable regions in the template. But if the rest of the design elements vary from what the template contains, Dreamweaver will preserve those tags alongside what the template will introduce which usually creates a ton of duplicated tags and broken layouts.
You would be FAR better off creating new, blank pages from the Dreamweaver Template and copy/pasting the contents into the editable area and then overwriting the "old" pages with the Save As command.
I just encountered this issue myself. I realize this original question was posted some time ago, but for anyone who might encounter this problem in the future, I am posting my solution.
If the only changes made to the template relate to one or more elements contained in an attached/linked file (such as a CSS style sheet or JS file), which changes Dreamweaver allows directly from the .dwt template itself, using the style boxes at the side/bottom, then Dreamweaver does not perceive any change to the actual .dwt file itself. If you want those changes to "take effect" and apply them to all pages, you might type a change to the .dwt file itself, click "save all" - undo the change and click "save all" again. This step is really not entirely necessary, as the changes to dependent files can be affected to the website by putting the dependent file to the website.
Also, Dreamweaver will apply changes to CSS/JS dependent files, across the board, but may continue to use a cache, until closed and reopened.
I'm attempting to port some content from TWiki to MediaWiki and whereas the former seems to allow the uploading of spreadsheets, the latter does not. I'm not interested in displaying / previewing the spreadsheet - just a hyperlink would do fine.
I appreciate that I could store the Excel files 'off-wiki' and externally link to them, but it would be good to keep it all together if at all possible - otherwise we'll have to think about maintaining seperate but logically linked filesystems etc.
Also, I would like to keep it in its original form rather than converting to HTML / JPG etc.
Has anyone hit this problem and if so, how was it solved?
Look in LocalSettings.php. You can then add this line: $wgFileExtensions = array('png', 'gif', 'jpg', 'jpeg', 'svg', 'xls'); (or whichever extensions you want). But be aware that you might want to switch this off after you've done your transfer otherwise your server will quickly become full with files!
See also Manual:$wgFileExtensions
Can a web parser differentiate between static and dynamic text on a webpage?
For example there is a string on a webpage
Hello "Fantastic Four"
In this "Hello" is a static data and "Fantastic Four" is a dynamic data (say being populated form a database value)
Is it possible for web parser to detect which is a static and dynamic content?
I think that it's not possible. The client can't know anything about the executing code in the server, so there is no way that know if the text has been generated by PHP, ASP or any other language... or even is static.
You can look at the URL and HTTP headers to make an educated guess if the file was served statically (directly from the filesystem) or generated. Most "web page parsers" don't get this information, however, and almost all generated pages have static bits in them. (Sometimes those are included directly in the source code, or they could be from a template or SSI file.) Distinguishing those static bits from the rest is impossible.