简体   繁体   English

我可以“预生成”我的“动态”网站的所有可能的静态html页面吗?

[英]Can I “pre-generate” all possible static-html pages of my “dynamic” website?

Some websites like for example http://www.idealo.co.uk seem to serve only static html , although their content is dynamic. 某些网站(例如http://www.idealo.co.uk)似乎只提供static html ,尽管它们的内容是动态的。

For example if I navigate through a certain category, I get a link to a static html page: 例如,如果我浏览某个类别,则会获得指向static html页面的链接:

http://www.idealo.co.uk/cat/5666/electric-guitars.html http://www.idealo.co.uk/cat/5666/electric-guitars.html

Now if I apply a custom filter, again I get a link to something that seems to be static html : 现在,如果我应用了一个自定义过滤器,我又得到了指向似乎是static html

http://www.idealo.co.uk/cat/5666F456496-735760-1502100/electric-guitars.html http://www.idealo.co.uk/cat/5666F456496-735760-1502100/electric-guitars.html

How is this achieved? 如何实现的? Are there any frameworks out there that help to "pre-generate" all possible dynamic pages, in such way that whenever a new input is given, the page already exists (ie the static html is already available)? 有没有可用的框架来“预生成”所有可能的动态页面,从而每当给出新输入时该页面就已经存在(即static html已经可用)?

Background: we run a small search engine for real estate offers. 背景:我们针对房地产报价运行了一个小型搜索引擎。 Offers are updated by our scrapper once a day (the content is static through the day). 优惠每天由我们的抓取工具更新一次(内容全天都是静态的)。 The content is searchable on a Ruby-on-Rails website. 可以在Ruby-on-Rails网站上搜索内容。 As the traffic increases, performance is becoming an issue. 随着流量的增加,性能正成为一个问题。 I'm wondering if there is any framework / tool that could batch-generate all our searches so that we could serve static html . 我想知道是否有任何框架/工具可以批量生成所有搜索,以便我们可以提供static html

Their site isn't dynamic. 他们的网站不是动态的。 They're using URL rewriting (eg mod_rewrite ) to translate the input URLs into a request that can be satisfied by a script. 他们使用URL重写(例如mod_rewrite )将输入的URL转换为脚本可以满足的请求。

For example: 例如:

/cat/5666/electric-guitars.html

Might be rewritten to: 可能被重写为:

/cat.php?id=5666

A quick trick to test this is to go to /cat/5666/foo.html 一个简单的测试方法是转到/cat/5666/foo.html

The use of .html in this case is probably to hide what kind of scripting is used on their site, as a weak security-through-obscurity measure. 在这种情况下,使用.html可能是为了掩盖其网站上使用的脚本类型,这是一种安全性低的模糊测试方法。

In response to your problem - no, there's no (easy) way to generate all possible results into static HTML files. 针对您的问题-不,没有(简单)的方法可以将所有可能的结果生成到静态HTML文件中。 You're looking at potentially billions of permutations. 您正在寻找潜在的数十亿个排列。 If you're having performance issues, look into performance profiling, caching, query optimisation, etc. 如果您遇到性能问题,请查看性能分析,缓存,查询优化等。

What you're describing is, in a sense, caching. 从某种意义上说,您描述的是缓存。 With caching your application will generate pages (and even parts of pages) only when their content has changed. 通过缓存,您的应用程序仅在内容更改时才会生成页面(甚至页面的一部分)。 Rails has a lot of cache functionality built in, which you can tune to fit your needs. Rails内置了许多缓存功能,您可以对其进行调整以满足自己的需求。 Start by reading the Rails Guide on caching which describes the Rails' capabilities as well as common add-ons. 首先阅读有关缓存Rails指南,指南描述了Rails的功能以及常见的附件。 Google around for "Rails 3 caching"—there's tons of information out there. Google到处寻找“ Rails 3缓存” —那里有大量信息。 Finally, you can add software to your server stack that does additional caching, such as Squid and Varnish. 最后,您可以将软件添加到服务器堆栈中,以进行额外的缓存,例如Squid和Varnish。 With the right tools (and research) you can get 95% of the benefit of a static site without the effort of turning your site into a quasi-static Frankenapp by hand. 借助正确的工具(和研究工具),您可以获得95%的静态站点收益,而无需手动将站点变成准静态的Frankenapp。

I finally found this blog post , which points to a few tools that do what I was looking for. 我终于找到了这篇博客文章 ,其中指出了一些可以满足我所需要的工具。 I'm adding it here just for future reference: 我在这里添加它只是为了将来参考:

Hyde 海德

"Hyde is a static website generator powered by Python & Django. Hyde supports all the Django template tags & filters and even has a few of its own. The built-in web server + auto-generator provide instant refresh and unlimited flexibility..." “ Hyde是由Python和Django支持的静态网站生成器。Hyde支持所有Django模板标签和过滤器,甚至拥有一些自己的模板。内置的Web服务器+自动生成器可提供即时刷新和无限的灵活性... “

Jekyll 杰奇

"Jekyll is a simple, blog-aware, static site generator. It takes a template directory containing raw text files in various formats, runs it through Markdown (or Textile) and Liquid converters, and spits out a complete, ready-to-publish static website suitable for serving with your favorite web server..." “ Jekyll是一个简单的,可识别博客的静态站点生成器。它获取包含各种格式的原始文本文件的模板目录,通过Markdown(或Textile)和Liquid转换器对其进行运行,并吐出一个完整的,随时可发布的文件适用于您喜欢的Web服务器的静态网站...”

blatter 空谈

"Blatter is a tiny tool for creating and publishing static web sites built from dynamic templates..." “ Blatter是一个用于创建和发布由动态模板构建的静态网站的微型工具……”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM