Static content linking

Last post 05-09-2008 2:51 AM by nagir. 0 replies.

Sort Posts:

  • Static content linking

    05-09-2008, 2:51 AM
    • Loading...
    • nagir
    • Joined on 01-09-2006, 7:01 PM
    • Australia
    • Posts 84

    Hi,

    Sorry for a long post. I didn't mean to do it :)
    I tried to structure my thought, but sorry if I failed :) I probably had to write a blog post.

    While Routnig is a great thing and it allows easy changing the structure of URL, it doesn't work with static content.
    So changing routing can just break some pages (when "direcory" structure is changed).

    Main 2 problems:

    1. Reference static resource from page (relative paths are not, generally, preserved after routing is changed) Good sample.
    2. Reference dynamic page from static resource. For example, new Ajax.Request("../../Home/RetrieveUsersOnline.aspx"). It will be broken after changing routing that produces link "/Users/Online/GetTop" instead first one.

    Also with fixed file structure I usually use combination of ASPX+CSS+JS located in the same folder. So the each page can additionally include its own resources.
    Typical MVC file structure has Views folder and, probably, should be protected, so we cannot put per-page resources there. So all of them should go into other folder. For example, Resources.

    But this not nice to develop because of we'll have Views/Home/Index.aspx file with Resources/Home/Index.css, Resources/Home/Index.js etc.

     
    So my questions

    Q1) What is the best way to reference static content from dynamic page?

    1. Use Url.Content.
    2. <a runat="server" href="~/Content/SomeResource" />.
    3. Application helper like App.Content.Link("SomeResource"). My preference.
    4. What else?

     

    Q2) What is the best way to reference dynamic content from static?

    1. Follow convention and never change routing (eg: "/Users/Online/GetTop")
    2. Follow convention but create alias routes for such references (eg: create alias "/Dynamic/Users/Online/GetTop" for "/Users/Online/GetTop").
      So while the page routes can be changed, links to dynamic content will be the same. For now my preference.
    3. Handle static content by ASP.NET and parse it (eg: write static content like this new Ajax.Request("<%#Url.Reference<UsersController>(x=>xGetTopUsersOnline)%>"). Too bloated.
    4. What else?

     

    Q3) What is the best way to include per-page resources (Page.aspx should include number of Page.css, Page.js etc) from views?

    1. Put all per-page resources into a separate folder (Content/Pages or so) folder and follow a convention.
    2. Put per-page resources under Views/Home folder and reference them like so Url.Content("Views/Home/Index/Index.js"). Not good if Views folder should be private.
    3. Follow a convention (per-page resources are located under Resources folder). And generate link like so "Resources/Home/Index/Index.js" using Url.Reference("index.js"). It will take current controller and  view name (not action - many actions can render the same view) and will concat it to "Resources/{Controller}/{ViewPage}/{File}".
    4. What else?


    What do you think about it?

    Cheers,
    Dmitriy.

    Filed under: ,
Page 1 of 1 (1 items)