dreamwest Posted December 22, 2010 Share Posted December 22, 2010 I wanted to include a static menu, but istead have it cached by an external js file. Is this a good idea, are there any security flaws in doing this?? js file function show_menu(){ document.write("menu menu menu menu"); return; } and the menu.html <script type="text/javascript" src="menu.js"></script> <body onload='show_menu();'> Quote Link to comment Share on other sites More sharing options...
n3r0x Posted December 22, 2010 Share Posted December 22, 2010 I see one problem <script type="text/javascript" src="menu.js"></script> <body onload='show_menu();'> Body onload are not triggered until the whole page is loaded.. and would be printed out on the bottom of the page. below the <body></html> and the site wouldn´t be to w3c standards. I would use <script type="text/javascript" src="menu.js"></script> <script type="text/javascript">show_menu();</script> As for security no real validation security should be done in javascript since anyone with a bit of time and a few plugins could bypass it. But here this code is harmless unless you include your admin menu in the "menu.js" file aswell. The less the hacker knows, the harder it is for him to hack it. Quote Link to comment Share on other sites More sharing options...
Adam Posted December 22, 2010 Share Posted December 22, 2010 Using JavaScript to generate a menu is an awful idea. How will crawlers navigate your site? Quote Link to comment Share on other sites More sharing options...
dreamwest Posted December 22, 2010 Author Share Posted December 22, 2010 Using JavaScript to generate a menu is an awful idea. How will crawlers navigate your site? What i really wanted to do was store part of the page such as the menu in memory. Im just not sure how to go about it without using a 3rd party app like eaccelerator - theres gotta be some way to do it.. Quote Link to comment Share on other sites More sharing options...
RichardRotterdam Posted December 22, 2010 Share Posted December 22, 2010 Using JavaScript to generate a menu is an awful idea. How will crawlers navigate your site? +1 What i really wanted to do was store part of the page such as the menu in memory. Im just not sure how to go about it without using a 3rd party app like eaccelerator - theres gotta be some way to do it.. What exactly do you mean by "store part of the page such as the menu in memory"? Quote Link to comment Share on other sites More sharing options...
haku Posted December 22, 2010 Share Posted December 22, 2010 The actual HTML to generate a menu is so minimal, there isn't even really any reason to cache it in the browser. It's a very, very small portion of the page. If you even have one tiny image on your page, it will take up significantly more data than any menu on any website ever (assuming your menu doesn't use images! But even if it does, you should just cache the images, not the HTML). Quote Link to comment Share on other sites More sharing options...
dreamwest Posted December 23, 2010 Author Share Posted December 23, 2010 The actual HTML to generate a menu is so minimal, there isn't even really any reason to cache it in the browser. It's a very, very small portion of the page. If you even have one tiny image on your page, it will take up significantly more data than any menu on any website ever (assuming your menu doesn't use images! But even if it does, you should just cache the images, not the HTML). Im just obsessed with instant page loading, ive had some good success with preprocessors and compression. The page loading time has been reduced to (Time: 0.076079) front end, but thats with menus, if i can store the template in the servers memory im assuming that would so the trick. Anyways i havent given up.. Quote Link to comment Share on other sites More sharing options...
haku Posted December 23, 2010 Share Posted December 23, 2010 As others have said, you're ruining your SEO if you do this. But if you absolutely must, then you should load the proper menu HTML the first time, and store it in a cookie. On subsequent page loads, if the cookie is present, load it from the cookie. This way it's on the users computer like you want, but the search engines will still get the benefit of getting the menu since it actually is loaded the first time. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.