+ All Categories
Home > Documents > 18 Ways Your Brand New ASP.NET MVC Project Can - Amazon S3

18 Ways Your Brand New ASP.NET MVC Project Can - Amazon S3

Date post: 09-Feb-2022
Category:
Upload: others
View: 1 times
Download: 0 times
Share this document with a friend
56
18 Ways Your Brand New ASP.NET MVC Project Can Be Better by Michael Kennedy DevelopMentor @mkennedy http://www.michaelckennedy.net from DEVELOPMENTOR - ONLINE, COLLABORATIVE, LEARNING PLATFORM. Warning: US English ahead, sorry my UK friends!
Transcript
Page 1: 18 Ways Your Brand New ASP.NET MVC Project Can - Amazon S3

18 Ways Your Brand New ASP.NET MVC Project Can Be Better

by Michael KennedyDevelopMentor

@mkennedyhttp://www.michaelckennedy.net

from DEVELOPMENTOR - ONLINE, COLLABORATIVE, LEARNING PLATFORM.

Warning: US English ahead, sorry my UK friends!

Page 2: 18 Ways Your Brand New ASP.NET MVC Project Can - Amazon S3

BonusThat's a bonus of 9 Ways!

OId Title:

9 Ways Your Brand New MVC 3 Project Can Be Better

ASP.NET MVC 4 has adopted many of the recommendations from the community.

Learn more at http://story.learninglineapp.com

Page 3: 18 Ways Your Brand New ASP.NET MVC Project Can - Amazon S3

Let's Start Here

Free for DewWeek attendees: http://bit.ly/ll-kennedy

Page 4: 18 Ways Your Brand New ASP.NET MVC Project Can - Amazon S3

MVC 4 is a major improvement - a quick reviewHere are some of the recommendations for new MVC 3 projects:

1. Delete the Microsoft MVC scripts (e.g. MicrosoftMvcValidation.js).2. Update your NuGet packages (more on this later).3. Create a separate space for your JavaScript vs NuGet's JavaScript.4. Minify your CSS in production.5. Create a JavaScript intellisense import for common libs, e.g. jQuery.6. Remove unused NuGet and JavaScript packages, e.g. jQueryUI.7. Add a reset.css file to help avoid style differences across browsers.8. Create a ViewModels folder.9. Move script imports to the bottom of layouts (except Modernizr.js).

10. Create a partial view which normalizes JavaScript imports.

from DEVELOPMENTOR - ONLINE, COLLABORATIVE, LEARNING PLATFORM.

Page 5: 18 Ways Your Brand New ASP.NET MVC Project Can - Amazon S3

MVC 4 is a major improvement - a quick reviewWhat has MVC 4 adopted out of the box? Gray items no longer necessary:

1. Delete the Microsoft MVC scripts (e.g. MicrosoftMvcValidation.js).2. Update your NuGet packages (less out of date).3. Create a separate space for your JavaScript vs NuGet's JavaScript.4. Minify your CSS in production.5. Create a JavaScript intellisense import for common libs, e.g. jQuery.6. Remove unused NuGet and JavaScript packages, e.g. jQueryUI.7. Add a reset.css file to help avoid style differences across browsers.8. Create a ViewModels folder.9. Move script imports to the bottom of layouts (except Modernizr.js).

10. Create a partial view which normalizes JavaScript imports.

Learn more at http://story.learninglineapp.com

Page 6: 18 Ways Your Brand New ASP.NET MVC Project Can - Amazon S3

MVC 4 is a major improvement - a quick review

Free for DewWeek attendees: http://bit.ly/ll-kennedy

Page 7: 18 Ways Your Brand New ASP.NET MVC Project Can - Amazon S3

1.

from DEVELOPMENTOR - ONLINE, COLLABORATIVE, LEARNING PLATFORM.

Page 8: 18 Ways Your Brand New ASP.NET MVC Project Can - Amazon S3

1. Your NuGet packages are already out of date

NuGet is awesome, but...

Learn more at http://story.learninglineapp.com

Page 9: 18 Ways Your Brand New ASP.NET MVC Project Can - Amazon S3

1. Your NuGet packages are already out of date

Updating each package via the UI is painful. Do it in one shot with a command:

Free for DewWeek attendees: http://bit.ly/ll-kennedy

Page 10: 18 Ways Your Brand New ASP.NET MVC Project Can - Amazon S3

1. Your NuGet packages are already out of date

But you *might* want to look into jQuery Migrate (also on NuGet)

https://github.com/jquery/jquery-migrate#readme

from DEVELOPMENTOR - ONLINE, COLLABORATIVE, LEARNING PLATFORM.

Page 11: 18 Ways Your Brand New ASP.NET MVC Project Can - Amazon S3

2.

Learn more at http://story.learninglineapp.com

Page 12: 18 Ways Your Brand New ASP.NET MVC Project Can - Amazon S3

2. Turn on NuGet package restore

Free for DewWeek attendees: http://bit.ly/ll-kennedy

Page 13: 18 Ways Your Brand New ASP.NET MVC Project Can - Amazon S3

3.

from DEVELOPMENTOR - ONLINE, COLLABORATIVE, LEARNING PLATFORM.

Page 14: 18 Ways Your Brand New ASP.NET MVC Project Can - Amazon S3

3. CSS on top, JavaScript on the bottom

JavaScript requests are blocking, let's load the UI first.

But what about

● Inline script?● Optional scripts?

Modernizr.js is special.

Learn more at http://story.learninglineapp.com

Page 15: 18 Ways Your Brand New ASP.NET MVC Project Can - Amazon S3

4.

Free for DewWeek attendees: http://bit.ly/ll-kennedy

Page 16: 18 Ways Your Brand New ASP.NET MVC Project Can - Amazon S3

4. Don't commingle your JavaScript with NuGet's

NuGet is awesome, but...

this is already crowded.

Make your own space.

from DEVELOPMENTOR - ONLINE, COLLABORATIVE, LEARNING PLATFORM.

Page 17: 18 Ways Your Brand New ASP.NET MVC Project Can - Amazon S3

5.

Learn more at http://story.learninglineapp.com

Page 18: 18 Ways Your Brand New ASP.NET MVC Project Can - Amazon S3

5. Minify your CSS in production

MVC 4 introduces minification as a feature of the framework. Use it.

Free for DewWeek attendees: http://bit.ly/ll-kennedy

Page 19: 18 Ways Your Brand New ASP.NET MVC Project Can - Amazon S3

6.

from DEVELOPMENTOR - ONLINE, COLLABORATIVE, LEARNING PLATFORM.

Page 20: 18 Ways Your Brand New ASP.NET MVC Project Can - Amazon S3

6. Add real jQuery intellisense

Before After

http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.9.1-vsdoc.js

Learn more at http://story.learninglineapp.com

Page 21: 18 Ways Your Brand New ASP.NET MVC Project Can - Amazon S3

7.

Free for DewWeek attendees: http://bit.ly/ll-kennedy

Page 22: 18 Ways Your Brand New ASP.NET MVC Project Can - Amazon S3

7. Use a reset CSS file

from DEVELOPMENTOR - ONLINE, COLLABORATIVE, LEARNING PLATFORM.

credit: http://www.hyperwrite.com/articles/showarticle.aspx?id=68

Programming on the web is awesome,except when it's not.

Browser inconsistencies are really frustrating. Reset CSS files can help.

Page 23: 18 Ways Your Brand New ASP.NET MVC Project Can - Amazon S3

7. Use a reset CSS file

Find a reset file at http://www.cssreset.com/

I personally like Normalize.css best.

Learn more at http://story.learninglineapp.com

Page 24: 18 Ways Your Brand New ASP.NET MVC Project Can - Amazon S3

8.

Free for DewWeek attendees: http://bit.ly/ll-kennedy

Page 25: 18 Ways Your Brand New ASP.NET MVC Project Can - Amazon S3

Learn more at http://story.learninglineapp.com

8. Create a ViewModels folder

This is a problem!

What goes in this folder? In real apps, you use data access assemblies, not just a folder.

Page 26: 18 Ways Your Brand New ASP.NET MVC Project Can - Amazon S3

8. Create a ViewModels folder

Now that's something I can work with!

I know what goes in these green boxes.

Learn more at http://story.learninglineapp.com

Page 27: 18 Ways Your Brand New ASP.NET MVC Project Can - Amazon S3

9.

Free for DewWeek attendees: http://bit.ly/ll-kennedy

Page 28: 18 Ways Your Brand New ASP.NET MVC Project Can - Amazon S3

Learn more at http://story.learninglineapp.com

9. Define a partial view for all your JavaScript imports.

Page 29: 18 Ways Your Brand New ASP.NET MVC Project Can - Amazon S3

9. Define a partial view for all your JavaScript imports.

You may want two JavaScript partial views

1. External imports (jquery, jqueryval, knockout, etc)

2. Your app's code (core.js. store.js, etc) that you built.

Learn more at http://story.learninglineapp.com

Page 30: 18 Ways Your Brand New ASP.NET MVC Project Can - Amazon S3

10.

Free for DewWeek attendees: http://bit.ly/ll-kennedy

Page 31: 18 Ways Your Brand New ASP.NET MVC Project Can - Amazon S3

Learn more at http://story.learninglineapp.com

10. Import your JavaScript files at the bottom.

You had to invent this in MVC 3.

Now it's just part of MVC.

But you still need to know how to use it.

Page 32: 18 Ways Your Brand New ASP.NET MVC Project Can - Amazon S3

10. Import your JavaScript files at the bottom.

Does this still work?

(regardless of whether it's a good idea)

Learn more at http://story.learninglineapp.com

Page 33: 18 Ways Your Brand New ASP.NET MVC Project Can - Amazon S3

11.

Free for DewWeek attendees: http://bit.ly/ll-kennedy

Page 34: 18 Ways Your Brand New ASP.NET MVC Project Can - Amazon S3

Learn more at http://story.learninglineapp.com

11. Setup web deploy for easy and reliable deploys.

http://www.microsoft.com/web/gallery/install.aspx?appid=WDeploy

Page 35: 18 Ways Your Brand New ASP.NET MVC Project Can - Amazon S3

12.

Learn more at http://story.learninglineapp.com

Page 36: 18 Ways Your Brand New ASP.NET MVC Project Can - Amazon S3

12. Change your project's startup page.

What?!? Why must this happen!

Free for DewWeek attendees: http://bit.ly/ll-kennedy

Page 37: 18 Ways Your Brand New ASP.NET MVC Project Can - Amazon S3

Learn more at http://story.learninglineapp.com

12. Change your project's startup page.

Ah, better!

Page 38: 18 Ways Your Brand New ASP.NET MVC Project Can - Amazon S3

13.

Learn more at http://story.learninglineapp.com

Page 39: 18 Ways Your Brand New ASP.NET MVC Project Can - Amazon S3

13. Careful with your vendor prefixes in CSS

Look, CSS3 is awesome!

Wait, why are there three ways to say box sizing?

Free for DewWeek attendees: http://bit.ly/ll-kennedy

Page 40: 18 Ways Your Brand New ASP.NET MVC Project Can - Amazon S3

Learn more at http://story.learninglineapp.com

13. Careful with your vendor prefixes in CSS

http://leaverou.github.com/prefixfree/

Page 41: 18 Ways Your Brand New ASP.NET MVC Project Can - Amazon S3

13. Careful with your vendor prefixes in CSS

CSS3 IS awesome!

Learn more at http://story.learninglineapp.com

Page 42: 18 Ways Your Brand New ASP.NET MVC Project Can - Amazon S3

14.

from DEVELOPMENTOR - ONLINE, COLLABORATIVE, LEARNING PLATFORM.

Page 43: 18 Ways Your Brand New ASP.NET MVC Project Can - Amazon S3

14. Turn on Resharper's Analyze Errors

Do you see the error? Does Visual Studio?

Free for DewWeek attendees: http://bit.ly/ll-kennedy

Page 44: 18 Ways Your Brand New ASP.NET MVC Project Can - Amazon S3

14. Turn on Resharper's Analyze Errors

Learn more at http://story.learninglineapp.com

Page 45: 18 Ways Your Brand New ASP.NET MVC Project Can - Amazon S3

15.

from DEVELOPMENTOR - ONLINE, COLLABORATIVE, LEARNING PLATFORM.

Page 46: 18 Ways Your Brand New ASP.NET MVC Project Can - Amazon S3

15. Consider a front-end CSS framework

http://usablica.github.com/front-end-frameworks/compare.html

Free for DewWeek attendees: http://bit.ly/ll-kennedy

Page 47: 18 Ways Your Brand New ASP.NET MVC Project Can - Amazon S3

15. Consider a front-end CSS framework

Learn more at http://story.learninglineapp.com

Page 48: 18 Ways Your Brand New ASP.NET MVC Project Can - Amazon S3

16.

from DEVELOPMENTOR - ONLINE, COLLABORATIVE, LEARNING PLATFORM.

Page 49: 18 Ways Your Brand New ASP.NET MVC Project Can - Amazon S3

16. When possible, pre-cache your JavaScript files.

https://learninglineapp.com/account/register?returnUrl=https://learninglineapp.com/schedule

Free for DewWeek attendees: http://bit.ly/ll-kennedy

Page 50: 18 Ways Your Brand New ASP.NET MVC Project Can - Amazon S3

17.

Learn more at http://story.learninglineapp.com

Page 51: 18 Ways Your Brand New ASP.NET MVC Project Can - Amazon S3

17. Use JavaScript namespaces.

from DEVELOPMENTOR - ONLINE, COLLABORATIVE, LEARNING PLATFORM.

Page 52: 18 Ways Your Brand New ASP.NET MVC Project Can - Amazon S3

18.

Free for DewWeek attendees: http://bit.ly/ll-kennedy

Page 53: 18 Ways Your Brand New ASP.NET MVC Project Can - Amazon S3

18. Catch and avoid multiple JavaScript file loads.

http://blog.michaelckennedy.net/2012/10/11/preventing-javascript-files-from-loading-multiple-times/

Learn more at http://story.learninglineapp.com

Page 54: 18 Ways Your Brand New ASP.NET MVC Project Can - Amazon S3

Summary 1. Your NuGet packages are already out of date - update them.

2. Turn on NuGet package restore.

3. CSS on top, JavaScript on the bottom.

4. Don't commingle your JavaScript with NuGet's.

5. Minify your CSS in production.

6. Add real jQuery intellisense.

7. Use a reset CSS file.

8. Create a ViewModels folder.

9. Define a partial view for all your JavaScript imports.

from DEVELOPMENTOR - ONLINE, COLLABORATIVE, LEARNING PLATFORM.

Page 55: 18 Ways Your Brand New ASP.NET MVC Project Can - Amazon S3

Summary (cont.)10. Import your JavaScript files at the bottom of the page.

11. Setup web deploy for easy and reliable deploys.

12. Change your project's startup page.

13. Careful with your vendor prefixes in CSS.

14. Turn on Resharper's Analyze Errors.

15. Consider a front-end CSS framework.

16. When possible, pre-cache your JavaScript files.

17. Use JavaScript namespaces.

18. Catch and avoid multiple JavaScript file loads.

Free for DewWeek attendees: http://bit.ly/ll-kennedy

Page 56: 18 Ways Your Brand New ASP.NET MVC Project Can - Amazon S3

Thanks for coming!

Free for DewWeek attendees: http://bit.ly/ll-kennedy

STAY IN TOUCH

Blog: blog.michaelckennedy.net

Twitter: @mkennedy

Google+: http://bit.ly/kennedy-plus


Recommended