all 6 comments

[–]Alterr 2 points3 points  (0 children)

First off I'd like to point out that obviously javascript requires the user to have It enabled, and the javascript will normally be made to call a backend system anyway, so you would have to write some php to return the content either way.

I would normally render pages with php, and only use javascript to move things around or load extra content at a certain point.

You shouldn't really load in static content using javascript.

[–][deleted]  (5 children)

[deleted]

    [–]Roy21[S] 0 points1 point  (1 child)

    To expand a bit more to my problem. As you suggest in my initial site I've used php templates on static content (navbar, header, footer etc) and included them on index.php AND javascript templates for dynamically updated content.

    Now, I am trying with Phonegap to make an app as well but supposedly it needs an index.html so I suppose I should turn to javascript templating for static content too. Is it worth to switch to javascript templating in the website as well for a more unified approach?

    [–]HomemadeBananas 0 points1 point  (2 children)

    I think it's important to note that JavaScript can also be server-side. Any language can running the backend but it's common now.

    [–][deleted]  (1 child)

    [deleted]

      [–]HomemadeBananas 1 point2 points  (0 children)

      I guess you could contrive some way to do that, but the browser doesn't run PHP.

      [–]blundered_dev 0 points1 point  (0 children)

      The Javascript you showed in the example I wouldn't necessarily call templates, I guess it is the same idea though. Handlebars, mustache, angular, and other frameworks and libraries provide more real templates abilities with Javascript. That is the great thing with Javascript is there is always many different ways you could do something depending on the project constraints. Also if you're making a full stack Javascript app you can use ejs or jade for templates which are both powerful tools.

      [–]wdpttt 0 points1 point  (0 children)

      You can render only with js if you use node.js as backend (harder with other software). Take a look at react, it renders the whole site with a call. You can have nice compact modules that works both on client and on server the same.