Dump my MVC site to static files
Asked Answered
S

5

6

I want to build a simple site with MVC but then render the "pages" and corresponding "assets" (js, css, images, etc) to what one might call a "static site".

In other words, I don't want to deploy to an IIS server that supports MVC. I simply want to build the site in MVC then somehow parse those pages into static html/css/etc files and upload the site to a regular LAMP host.

Is there an easy way to automate this? NuGet package? Binary? MVC extension like maybe a handler add-on that can render out the static site in a single pass?

Sandell answered 11/6, 2012 at 4:15 Comment(0)
T
2

About 10 years back, I used to download whole websites for offline use using HTTrack Website Copier. May be you could download your own website which gives you nice hierarchy of your static web pages. If you think all your webpages are reachable through the homepage links, menu links etc then you can download most of your website. Basically you can google for web crawlers/ offline browsers/website downloaders etc. and run them to get your job done.

Alternatively if you know the pattern of urls, you could give it to download manager to download them. Not sure if it works with your website, but I do it sometimes.

HTH

Trice answered 11/6, 2012 at 17:5 Comment(1)
Some good ideas in there. I was hoping there was a more integrated way to do this... but these ideas will work as a "plan b". CheersSandell
P
1

If your site depends on a database or some other dynamic source it will be close to impossible to dump all possible combinations of pages into static files. If on the other hand your site is pretty much static, saving the rendered HTML/JS/CSS source into files and uploading it to a LAMP server won't be too hard.

Peripeteia answered 11/6, 2012 at 4:42 Comment(2)
Great. Everything is static - there are no conditionals. So when you say "won't be too hard", do you have somewhere I should start?Sandell
Yes, the view source option of your web browser.Peripeteia
C
1

You may wanna look at Pretzel, a .Net static site generator.

Update: Apparently it doesn't work on ASP.Net projects: Issue #123. It only supports Razor language for authoring content pages.

Chronology answered 26/3, 2013 at 19:58 Comment(0)
D
0

If the reason for doing this is performance related why not just use output caching and the like, that way the pages will be extremely fast (you could set the cache timeout to a very long period of time) and you don't need to run some tool to do the conversion and have to store your html separate to your source code.

Of course you will still need to run IIS/.net

Dibble answered 12/6, 2012 at 4:21 Comment(2)
It's not performance related. I just want the freedom to produce a simple, static site with the aid of Visual Studio and the MVC framework and then flatten it out to a static site that can be hosted anywhere.Sandell
take a look at asp.net web pages, wont help with converting it to static files I dont think but it is a more lightweight type of framework for more static content orientated sites and simpler sitesDibble
B
0

You have three options:

  1. Create your website using plain html, css, jquery and images. You can use Visual Studio Code as IDE to create the files. One issue might be to manage common header/footer for your website. But you can solve it by injecting html header/footer using jquery.

  2. Use a CMS (content management system) like Umbraco to host your static site. Umbraco indexes and caches pages to improve performance. You have great control on what to publish on your website etc.

  3. Create the website using .Net + MVC and use tools like HTTrack to download a static copy of the website. You can even automate the process using commands and triggering it after every deployment or build etc.

Baldachin answered 24/3, 2020 at 3:44 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.